CSES - HIIT Open 2018 - Results
Submission details
Task:Find a Word
Sender:DROP TABLE
Submission time:2018-05-26 15:39:31
Language:Java
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.32 sdetails
#2ACCEPTED0.33 sdetails
#3ACCEPTED0.38 sdetails
#4ACCEPTED0.37 sdetails
#5ACCEPTED0.36 sdetails
#6ACCEPTED0.38 sdetails
#7ACCEPTED0.34 sdetails
#8ACCEPTED0.33 sdetails
#9ACCEPTED0.32 sdetails
#10ACCEPTED0.37 sdetails
#11--details
#120.22 sdetails
#130.24 sdetails
#14--details
#150.25 sdetails
#160.22 sdetails

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){
		String s = "";
		s += table[y][x];
		if (y == n - 1 && x == n - 1){
			WORDS.add(s);
			return;
		}
		if(x < n - 1) {
			rec(y, x + 1, s);
		}
		if(y < n - 1) {
			rec(y + 1, x, s);
		}
	}
	public static void rec(int y, int x, String s){
		s += table[y][x];
		if (y == n - 1 && x == n - 1){
			WORDS.add(s);
			return;
		}
		if(x < n - 1) {
			rec(y, x + 1, s);
		}
		if(y < n - 1) {
			rec(y + 1, x, s);
		}
	}
	
	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:

input
30 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
...

correct output
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

user output
(empty)

Test 12

Verdict:

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:45)

Test 13

Verdict:

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:45)

Test 14

Verdict:

input
30 1
QNJPEVJUXHZFRXCVKBSJKUURVPLYUI
RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW
FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP
WYLTEQJBJRPSEMPOESVKFTQKEMSIAP
...

correct output
QNJLGFBBMJBHCCBOCEFBPLDCFGDJKB...

user output
(empty)

Test 15

Verdict:

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:45)

Test 16

Verdict:

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:45)