Task: | Peli |
Sender: | EmuBird |
Submission time: | 2024-01-20 16:39:53 +0200 |
Language: | Java |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.08 s | 1, 2 | details |
#2 | ACCEPTED | 0.19 s | 1, 2 | details |
#3 | RUNTIME ERROR | 0.76 s | 2 | details |
#4 | ACCEPTED | 0.17 s | 1, 2 | details |
#5 | WRONG ANSWER | 0.19 s | 1, 2 | details |
#6 | RUNTIME ERROR | 0.95 s | 2 | details |
#7 | RUNTIME ERROR | 0.67 s | 2 | details |
#8 | WRONG ANSWER | 0.77 s | 1, 2 | details |
#9 | TIME LIMIT EXCEEDED | -- | 2 | details |
#10 | RUNTIME ERROR | 0.61 s | 2 | details |
Code
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; public class Main { private static class Query { int from; int to; int moves; Query(int from, int to, int moves) { this.from = from; this.to = to; this.moves = moves; } @Override public int hashCode() { return Arrays.hashCode(new int[]{from, to, moves}); } } private static ArrayList<ArrayList<Integer>> paths = new ArrayList<>(); private static HashMap<Query, Boolean> queryMemory = new HashMap<>(); public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] inputLine1 = reader.readLine().trim().split(" "); int n = Integer.parseInt(inputLine1[0]); int m = Integer.parseInt(inputLine1[1]); int q = Integer.parseInt(inputLine1[2]); for (int planet = 0; planet < n; planet++) { paths.add(new ArrayList<>()); } for (int pathIndex = 0; pathIndex < m; pathIndex++) { String[] inputLine2 = reader.readLine().trim().split(" "); int a = Integer.parseInt(inputLine2[0]) - 1; int b = Integer.parseInt(inputLine2[1]) - 1; paths.get(a).add(b); paths.get(b).add(a); } for (int i = 0; i < q; i++) { String[] inputLine3 = reader.readLine().trim().split(" "); int from = Integer.parseInt(inputLine3[0]) - 1; int to = Integer.parseInt(inputLine3[1]) - 1; int moves = Integer.parseInt(inputLine3[2]); System.out.println(query(new Query(from, to, moves)) ? "YES" : "NO"); } } private static boolean query(Query query) { if (queryMemory.containsKey(query)) return queryMemory.get(query); boolean result = false; if (query.from == query.to) { result = query.moves % 2 == 0; } else if (query.moves <= 0) { result = false; } else { int originalFrom = query.from; query.moves--; for (int destination : paths.get(query.from)) { query.from = destination; if (query(query)) { result = true; } } query.moves++; query.from = originalFrom; } queryMemory.put(query, result); return result; } }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
2 1 100 1 2 1 1 0 1 2 0 2 1 0 ... |
correct output |
---|
YES NO NO YES NO ... |
user output |
---|
YES NO NO YES NO ... Truncated |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
50 49 100 33 34 7 8 49 50 47 48 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... Truncated |
Test 3
Group: 2
Verdict: RUNTIME ERROR
input |
---|
2500 2499 100000 821 822 2351 2352 752 753 832 833 ... |
correct output |
---|
NO YES YES NO NO ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.StackOverflowError at Main.query(Main.java:73) at M...
Test 4
Group: 1, 2
Verdict: ACCEPTED
input |
---|
12 12 100 9 10 2 3 1 12 1 2 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... Truncated |
Test 5
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
11 11 100 10 11 7 8 1 2 5 6 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... Truncated |
Test 6
Group: 2
Verdict: RUNTIME ERROR
input |
---|
2500 2500 100000 1936 1937 1884 1885 751 752 831 832 ... |
correct output |
---|
NO YES YES NO NO ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.StackOverflowError at Main.query(Main.java:73) at M...
Test 7
Group: 2
Verdict: RUNTIME ERROR
input |
---|
2499 2499 100000 821 822 2351 2352 752 753 832 833 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.StackOverflowError at Main.query(Main.java:73) at M...
Test 8
Group: 1, 2
Verdict: WRONG ANSWER
input |
---|
50 99 100 40 47 34 50 44 47 15 16 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... Truncated |
Test 9
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
2500 4999 100000 1191 2361 251 399 1026 2300 82 1655 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
(empty) |
Test 10
Group: 2
Verdict: RUNTIME ERROR
input |
---|
2500 4999 100000 2023 2218 23 51 1020 1272 11 114 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.StackOverflowError at Main.query(Main.java:73) at M...