Task: | Find a Word |
Sender: | DROP TABLE |
Submission time: | 2018-05-26 15:34:36 +0300 |
Language: | Java |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.28 s | details |
#2 | ACCEPTED | 0.25 s | details |
#3 | ACCEPTED | 0.29 s | details |
#4 | ACCEPTED | 0.27 s | details |
#5 | ACCEPTED | 0.23 s | details |
#6 | ACCEPTED | 0.27 s | details |
#7 | ACCEPTED | 0.24 s | details |
#8 | ACCEPTED | 0.22 s | details |
#9 | ACCEPTED | 0.23 s | details |
#10 | ACCEPTED | 0.27 s | details |
#11 | TIME LIMIT EXCEEDED | -- | details |
#12 | RUNTIME ERROR | 0.24 s | details |
#13 | RUNTIME ERROR | 0.23 s | details |
#14 | TIME LIMIT EXCEEDED | -- | details |
#15 | RUNTIME ERROR | 0.26 s | details |
#16 | RUNTIME ERROR | 0.25 s | details |
Code
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main2 { static List<String> WORDS = new ArrayList<>(); static int n; static int k; static Scanner scanner = new Scanner(System.in); static char[][] table; public static void rec(int y, int x){ StringBuilder sb = new StringBuilder(); sb.append(table[y][x]); if(x < n - 1) { rec(y, x + 1, new StringBuilder(sb)); } if(y < n - 1) { rec(y + 1, x, new StringBuilder(sb)); } } public static void rec(int y, int x, StringBuilder sb){ sb.append(table[y][x]); if (y == n - 1 && x == n - 1){ WORDS.add(sb.toString()); return; } if(x < n - 1) { rec(y, x + 1, new StringBuilder(sb)); } if(y < n - 1) { rec(y + 1, x, new StringBuilder(sb)); } } public static void main(String[] args) { n = scanner.nextInt(); k = scanner.nextInt(); table = new char[n][n]; for(int i = 0; i < n; i++){ table[i] = scanner.next().toCharArray(); } rec(0,0); WORDS.sort(null); //System.out.println(WORDS); System.out.println(WORDS.get(k-1)); } }
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: TIME LIMIT EXCEEDED
input |
---|
30 1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ... |
correct output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
user output |
---|
(empty) |
Test 12
Verdict: RUNTIME ERROR
input |
---|
30 15033633249770520 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ... |
correct output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "15033633249770520" at java.base/java.util.Scanner.nextInt(Scanner.java:2264) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Main2.main(Main2.java:41)
Test 13
Verdict: RUNTIME ERROR
input |
---|
30 30067266499541040 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ... |
correct output |
---|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "30067266499541040" at java.base/java.util.Scanner.nextInt(Scanner.java:2264) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Main2.main(Main2.java:41)
Test 14
Verdict: TIME LIMIT EXCEEDED
input |
---|
30 1 QNJPEVJUXHZFRXCVKBSJKUURVPLYUI RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP WYLTEQJBJRPSEMPOESVKFTQKEMSIAP ... |
correct output |
---|
QNJLGFBBMJBHCCBOCEFBPLDCFGDJKB... |
user output |
---|
(empty) |
Test 15
Verdict: RUNTIME ERROR
input |
---|
30 15033633249770520 QNJPEVJUXHZFRXCVKBSJKUURVPLYUI RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP WYLTEQJBJRPSEMPOESVKFTQKEMSIAP ... |
correct output |
---|
QNXZYLYURTAYRYZQUKZCYOPKYKLQPX... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "15033633249770520" at java.base/java.util.Scanner.nextInt(Scanner.java:2264) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Main2.main(Main2.java:41)
Test 16
Verdict: RUNTIME ERROR
input |
---|
30 30067266499541040 QNJPEVJUXHZFRXCVKBSJKUURVPLYUI RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP WYLTEQJBJRPSEMPOESVKFTQKEMSIAP ... |
correct output |
---|
QRXZYLYURTAYRYZQUKZCYOPKYKLQPX... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "30067266499541040" at java.base/java.util.Scanner.nextInt(Scanner.java:2264) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Main2.main(Main2.java:41)