I can’t find why it does not work online : Timeout: the program did not provide 1 input lines in due time…
It’s okay on my IDE and returns within less than 50ms
import java.util.Scanner;
class Player {
public static String findDown(final boolean[][] cells, final int i, final int j, final int h) {
for (int y = j + 1; y < h; y++) {
if (cells[i][y]) {
return i + " " + y;
}
}
return -1 + " " + -1;
}
public static String findRight(final boolean[][] cells, final int i, final int j, final int w) {
for (int x = i + 1; x < w; x++) {
if (cells[x][j]) {
return x + " " + j;
}
}
return -1 + " " + -1;
}
public static void main(final String args[]) {
final long time = System.currentTimeMillis();
System.err.println("starting at " + time);
final Scanner in = new Scanner(System.in);
final int width = in.nextInt(); // the number of cells on the X axis
final int height = in.nextInt(); // the number of cells on the Y axis
if (in.hasNextLine()) {
in.nextLine();
}
final boolean[][] cells = new boolean[width][height];
int lineNumber = 0;
while (in.hasNextLine()) {
final String line = in.nextLine(); // width characters, each either 0 or .
for (int c = 0; c < line.length(); c++) {
cells[c][lineNumber] = line.charAt(c) == '0';
}
lineNumber++;
}
System.err.println("cells is built in " + (System.currentTimeMillis() - time));
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (cells[i][j]) {
final String cell = i + " " + j + " "
+ Player.findRight(cells, i, j, width) + " "
+ Player.findDown(cells, i, j, height);
System.out.println(cell);
}
}
}
System.err.println("finished in " + (System.currentTimeMillis() - time));
}
}
you can’t use while (in.hasNextLine()) {
after reading all the inputs, the scanner blocks waiting for another input, hence the timeout. A simple loop for on height will solve your day
Hello,
There are two weird things when i launch this code : (i don’t know how to put it more nice sorry)
import sys
import math
def vDroite(x,y):.........
def vBas(x,y):...............
width = int(input())
height = int(input())
tab=[]
for i in range(height):
->->line = input()
->->tab.append(list(line))
for i in width:
->->for j in height:
->->->->if tab[j][i]=='0':
->->->->->->print(str(i)+" "+str(j)+" "+vDroite(i,j)+" "+vBas(i,j)
Sortie d’erreur :
SyntaxError: unexpected EOF while parsing
at Answer.py. not in a function on line 38
Informations :
Initializing APU weaponry…
Informations :
Timeout: the program did not provide 1 input lines in due time…
I don’t understand the last message : why doesn’t the input come ???
And as for the problem on line 38…it doesn’t exist ! My last line is 36, so how can there be a problem ?
Thanks for your help !
This is because you create the list, in a way that you must not.
By typing: array = [[0]*width]*height, you make a list with five references to the same list (in our case, array.
You should write this instead: array= [[0]*width for _ in range(height)
Hello, im trying to solve there is no spoon, but i get issues . Here is my code :
import sys
import math
# Don't let the machines win. You are humanity's last hope...
width = int(input()) # the number of cells on the X axis
height = int(input()) # the number of cells on the Y axis
M = [['0' for i in range(width)] for k in range(height)]
for i in range(height): # i take input and put in inside my matrix
line = input()
for j in range(len(line)) :
M[i][j] = line[j]
for i in range(height) : # this double loop allows me to actually print the answer
for j in range(width) :
if M[i][j] == "0": #are we on a node ?
res = str(j)+" "+str(i) +' '
if j != width-1 : #are we on the right edge ?
if M[i][j+1] == '0': #if not on right edge, does the node have a right neighboor ?
res += str(j+1) +' '+str(i)+" "
if i != height -1 : #are we on the bottom ?
if M[i+1][j] == '0': res += str(j) +' '+str(i+1) # if not, is bottom neighboor a node ?
else : res+= '-1 -1'#if no neighbour send -1 -1
else : res+= '-1 -1'#if we are bottom, send -1 -1 (no neighbour possible)
else : #no right neighbour
res+= '-1 -1 '
if i != height -1 : #check if we at bottom
if M[i+1][j] == '0': res += str(j) +' '+str(i+1) # check bottom neighbour
else : res+= '-1 -1' #no bottom neighbour send -1 -1
else : res+= '-1 -1' #bottom
else : #we are right edge
res+= '-1 -1 '
if i != height -1 : #bottom ?
if M[i+1][j] == '0': res += str(j) +' '+str(i+1) #bottom neighbour ?
else : res+= '-1 -1' #no bottom neighbour
else : res+= '-1 -1' #edge and bottom == south right corner
print(res) #display the concatenated solution
since we need all the input to get all the neighbour, i first took input and put it inside a matrix. then i search trough the matrix and put conditions to get the result. but i dont know if i can do it this way. i have 50 complete. Thanks for your feed back
Copy paste your script, select it and click on </> icon.
Your code is hard to read right now but a general advice:
instead of printing a str, use variables (e.g a, b, c, d) and once you determined their value, print(j, i, a, b, c, d).
It will be much easier to read that way.
Hello there,
I think there is an instability in your tests, at least for clojure runs.
For proofs i have submitted 2 times the same code and failed at different tests.
It happens sometimes in the IDE tests to sometimes, and the Error says that the input was not read, but what’s happening (i bet) is that the process failed to start.
I’ll try creating inputs and test-it locally.
Since i have picked up this language 3 days ago it might be it.
However if the program did timed out, the debug (stderr) output should still be printed at least, right ?
I did put an init message as the first thing to be executed, nothing appeared, but still crashed.
I made some puzzles with clojure, and never encountered any problem. It is possible that there’s a problem on the site side, but it’s necessary to be sure that’s not from your code before making a bug report.