Task: | Find a Word |
Sender: | El Numero Uno |
Submission time: | 2018-05-26 15:58:32 +0300 |
Language: | Java |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.38 s | details |
#2 | ACCEPTED | 0.33 s | details |
#3 | ACCEPTED | 0.34 s | details |
#4 | ACCEPTED | 0.32 s | details |
#5 | ACCEPTED | 0.34 s | details |
#6 | ACCEPTED | 0.31 s | details |
#7 | ACCEPTED | 0.29 s | details |
#8 | ACCEPTED | 0.33 s | details |
#9 | ACCEPTED | 0.34 s | details |
#10 | ACCEPTED | 0.32 s | details |
#11 | ACCEPTED | 0.34 s | details |
#12 | RUNTIME ERROR | 0.27 s | details |
#13 | RUNTIME ERROR | 0.22 s | details |
#14 | WRONG ANSWER | 0.34 s | details |
#15 | RUNTIME ERROR | 0.24 s | details |
#16 | RUNTIME ERROR | 0.22 s | details |
Code
import java.util.*; class Coord { int x; int y; public Coord(int x, int y) { this.x = x; this.y=y; } } public class f { static int k; static List<String> finalStrings = new ArrayList<>(); private static List<Coord> getSurroundings(Coord coord, List<List<Character>> matrix) { Coord coord1 = null; Coord coord2 = null; if (coord.x+1 <= matrix.size()-1) { coord1 = new Coord(coord.x+1, coord.y); } if (coord.y+1 <= matrix.size()-1) { coord2 = new Coord(coord.x, coord.y+1); } if (coord1 == null && coord2 == null) { return Arrays.asList(); } if (coord1 == null) return Arrays.asList(coord2); if (coord2 == null) return Arrays.asList(coord1); if (matrix.get(coord1.x).get(coord1.y) < matrix.get(coord2.x).get(coord2.y)) { return Arrays.asList(coord1, coord2); } return Arrays.asList(coord2, coord1); } private static void solve(List<List<Character>> matrix, Coord coord, String currentString) { List<Coord> surroundings = getSurroundings(coord, matrix); if (surroundings.isEmpty()) { finalStrings.add(currentString); if (finalStrings.size() >= k) { System.out.println(finalStrings.get(k-1)); System.exit(0); } } List<String> strings = new ArrayList<>(); for (Coord c : surroundings) { String newString = currentString + String.valueOf(matrix.get(c.x).get(c.y)); solve(matrix, c, newString); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int a=0; if (in.hasNextLine()) { String line = in.nextLine(); String[] dimensions = line.split(" "); a = Integer.parseInt(dimensions[0]); k = Integer.parseInt(dimensions[1]); } List<List<Character>> matrix = new ArrayList<>(); for (int i = 0; i < a && in.hasNextLine(); i++) { String line = in.nextLine(); char[] charArray = line.toCharArray(); List<Character> lineList = new ArrayList<>(); for (char c : charArray) { lineList.add(c); } matrix.add(lineList); } solve(matrix,new Coord(0,0), String.valueOf(matrix.get(0).get(0))); } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
4 1 AAAA AAAA AAAA AAAA |
correct output |
---|
AAAAAAA |
user output |
---|
AAAAAAA |
Test 2
Verdict: ACCEPTED
input |
---|
4 2 AAAA AAAA AAAA AAAA |
correct output |
---|
AAAAAAA |
user output |
---|
AAAAAAA |
Test 3
Verdict: ACCEPTED
input |
---|
4 10 AAAA AAAA AAAA AAAA |
correct output |
---|
AAAAAAA |
user output |
---|
AAAAAAA |
Test 4
Verdict: ACCEPTED
input |
---|
4 19 AAAA AAAA AAAA AAAA |
correct output |
---|
AAAAAAA |
user output |
---|
AAAAAAA |
Test 5
Verdict: ACCEPTED
input |
---|
4 20 AAAA AAAA AAAA AAAA |
correct output |
---|
AAAAAAA |
user output |
---|
AAAAAAA |
Test 6
Verdict: ACCEPTED
input |
---|
4 1 QNJP EVJU XHZF RXCV |
correct output |
---|
QEVHXCV |
user output |
---|
QEVHXCV |
Test 7
Verdict: ACCEPTED
input |
---|
4 2 QNJP EVJU XHZF RXCV |
correct output |
---|
QEVHZCV |
user output |
---|
QEVHZCV |
Test 8
Verdict: ACCEPTED
input |
---|
4 10 QNJP EVJU XHZF RXCV |
correct output |
---|
QEXRXCV |
user output |
---|
QEXRXCV |
Test 9
Verdict: ACCEPTED
input |
---|
4 19 QNJP EVJU XHZF RXCV |
correct output |
---|
QNVJZCV |
user output |
---|
QNVJZCV |
Test 10
Verdict: ACCEPTED
input |
---|
4 20 QNJP EVJU XHZF RXCV |
correct output |
---|
QNVJZFV |
user output |
---|
QNVJZFV |
Test 11
Verdict: ACCEPTED
input |
---|
30 1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ... |
correct output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
user output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
Test 12
Verdict: RUNTIME ERROR
input |
---|
30 15033633249770520 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ... |
correct output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "15033633249770520" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at f.main(f.java:59)
Test 13
Verdict: RUNTIME ERROR
input |
---|
30 30067266499541040 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ... |
correct output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "30067266499541040" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at f.main(f.java:59)
Test 14
Verdict: WRONG ANSWER
input |
---|
30 1 QNJPEVJUXHZFRXCVKBSJKUURVPLYUI RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP WYLTEQJBJRPSEMPOESVKFTQKEMSIAP ... |
correct output |
---|
QNJLGFBBMJBHCCBOCEFBPLDCFGDJKB... |
user output |
---|
QNJLGFBBMJBHCCBOCEFBPLDCFGDJKB... |
Test 15
Verdict: RUNTIME ERROR
input |
---|
30 15033633249770520 QNJPEVJUXHZFRXCVKBSJKUURVPLYUI RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP WYLTEQJBJRPSEMPOESVKFTQKEMSIAP ... |
correct output |
---|
QNXZYLYURTAYRYZQUKZCYOPKYKLQPX... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "15033633249770520" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at f.main(f.java:59)
Test 16
Verdict: RUNTIME ERROR
input |
---|
30 30067266499541040 QNJPEVJUXHZFRXCVKBSJKUURVPLYUI RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP WYLTEQJBJRPSEMPOESVKFTQKEMSIAP ... |
correct output |
---|
QRXZYLYURTAYRYZQUKZCYOPKYKLQPX... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "30067266499541040" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at f.main(f.java:59)