There is no Spoon - Episode 1 puzzle discussion

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

Thanks, and it worked in my IDE because I was passing the input through “java Test < file” !

1 Like

The problem is “Timeout: the program did not provide 1 input lines in due time…”

I passed all the testcases but submit screen (‘loading… computing score’) takes forever for some reason

we had an issue with our “jobs”. It should be ok now

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 !