CSES - HIIT Open 2018 - Results
Submission details
Task:Find a Word
Sender:El Numero Uno
Submission time:2018-05-26 15:58:32 +0300
Language:Java
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.38 sdetails
#2ACCEPTED0.33 sdetails
#3ACCEPTED0.34 sdetails
#4ACCEPTED0.32 sdetails
#5ACCEPTED0.34 sdetails
#6ACCEPTED0.31 sdetails
#7ACCEPTED0.29 sdetails
#8ACCEPTED0.33 sdetails
#9ACCEPTED0.34 sdetails
#10ACCEPTED0.32 sdetails
#11ACCEPTED0.34 sdetails
#120.27 sdetails
#130.22 sdetails
#140.34 sdetails
#150.24 sdetails
#160.22 sdetails

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:

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:

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:

input
30 1
QNJPEVJUXHZFRXCVKBSJKUURVPLYUI
RXLGFBNQPBKQQRQFHLXUIUPLUOUOQW
FZNNUBMTLXUMTSJOOGBDBEVEYVWOLP
WYLTEQJBJRPSEMPOESVKFTQKEMSIAP
...

correct output
QNJLGFBBMJBHCCBOCEFBPLDCFGDJKB...

user output
QNJLGFBBMJBHCCBOCEFBPLDCFGDJKB...

Test 15

Verdict:

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:

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)