Task: | Jump |
Sender: | Kuha |
Submission time: | 2016-07-29 16:50:34 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.07 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | TIME LIMIT EXCEEDED | -- | details |
#5 | TIME LIMIT EXCEEDED | -- | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | TIME LIMIT EXCEEDED | -- | details |
#8 | TIME LIMIT EXCEEDED | -- | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | TIME LIMIT EXCEEDED | -- | details |
#11 | TIME LIMIT EXCEEDED | -- | details |
#12 | TIME LIMIT EXCEEDED | -- | details |
#13 | TIME LIMIT EXCEEDED | -- | details |
#14 | TIME LIMIT EXCEEDED | -- | details |
#15 | TIME LIMIT EXCEEDED | -- | details |
#16 | TIME LIMIT EXCEEDED | -- | details |
#17 | TIME LIMIT EXCEEDED | -- | details |
#18 | TIME LIMIT EXCEEDED | -- | details |
#19 | TIME LIMIT EXCEEDED | -- | details |
#20 | ACCEPTED | 0.11 s | details |
#21 | ACCEPTED | 0.11 s | details |
#22 | TIME LIMIT EXCEEDED | -- | details |
#23 | TIME LIMIT EXCEEDED | -- | details |
#24 | TIME LIMIT EXCEEDED | -- | details |
#25 | TIME LIMIT EXCEEDED | -- | details |
#26 | TIME LIMIT EXCEEDED | -- | details |
#27 | TIME LIMIT EXCEEDED | -- | details |
#28 | TIME LIMIT EXCEEDED | -- | details |
#29 | TIME LIMIT EXCEEDED | -- | details |
#30 | ACCEPTED | 0.13 s | details |
#31 | ACCEPTED | 0.12 s | details |
#32 | ACCEPTED | 0.14 s | details |
#33 | ACCEPTED | 0.12 s | details |
#34 | ACCEPTED | 0.12 s | details |
#35 | TIME LIMIT EXCEEDED | -- | details |
#36 | TIME LIMIT EXCEEDED | -- | details |
Code
#include <bits/stdc++.h> #define ll long long #define INF 999999999 #define LINF 999999999999999999LL #define N (1<<17) #define M 1000000007 using namespace std; unordered_map<int, int> c; unordered_map<int, vector<int>> v; unordered_map<int, int> e; void dfs (const int i, const int x) { if (c[i]) return; c[i] = x; for (int j : v[i]) dfs(j, x); } int main () { cin.tie(0); cin.sync_with_stdio(false); int n; cin>>n; for (int i = 0; i < n; i++) { int x; cin>>x; for (int i = -10000; i <= 20000; i++) v[i].push_back(2 * x - i); } int x = 0; for (int i = -10000; i <= 20000; i++) { if (c[i]) continue; x++; dfs(i, x); } int q; cin>>q; for (int i = 1; i <= q; i++) { int a, b; cin>>a>>b; if (c[a] != c[b]) cout<<-1<<endl; else { queue<pair<int, int>> q; q.push({a, 0}); while (true) { int j = q.front().first; int d = q.front().second; if (j == b) { cout<<d<<endl; break; } q.pop(); if (e[j] == i) continue; e[j] = i; for (int k : v[j]) q.push({k, d + 1}); } } } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
4 1 2 4 7 ... |
correct output |
---|
-1 -1 2 2 -1 ... |
user output |
---|
-1 -1 2 2 -1 ... |
Test 2
Verdict: ACCEPTED
input |
---|
4 1 2 6 10 ... |
correct output |
---|
-1 1 2 -1 1 ... |
user output |
---|
-1 1 2 -1 1 ... |
Test 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 12 14 30 101 ... |
correct output |
---|
2 2 1 2 2 ... |
user output |
---|
(empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 13 22 196 211 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 10 41 107 167 ... |
correct output |
---|
2 1 2 2 2 ... |
user output |
---|
(empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 91 166 275 278 ... |
correct output |
---|
2 2 2 3 2 ... |
user output |
---|
(empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 18 104 138 182 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 115 144 272 274 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 84 177 208 219 ... |
correct output |
---|
2 2 2 2 1 ... |
user output |
---|
(empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 96 131 228 258 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 11
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 0 77 132 189 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 12
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 3 33 74 118 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 95 162 171 448 ... |
correct output |
---|
-1 -1 2 2 2 ... |
user output |
---|
(empty) |
Test 14
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 32 72 229 239 ... |
correct output |
---|
2 -1 2 2 -1 ... |
user output |
---|
(empty) |
Test 15
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 30 124 136 176 ... |
correct output |
---|
2 -1 2 -1 2 ... |
user output |
---|
(empty) |
Test 16
Verdict: TIME LIMIT EXCEEDED
input |
---|
116 34 68 85 87 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 17
Verdict: TIME LIMIT EXCEEDED
input |
---|
112 64 264 268 298 ... |
correct output |
---|
2 2 2 2 2 ... |
user output |
---|
(empty) |
Test 18
Verdict: TIME LIMIT EXCEEDED
input |
---|
64 14 15 19 31 ... |
correct output |
---|
8 6 10 4 6 ... |
user output |
---|
(empty) |
Test 19
Verdict: TIME LIMIT EXCEEDED
input |
---|
200 0 1 2 3 ... |
correct output |
---|
14 14 8 6 40 ... |
user output |
---|
(empty) |
Test 20
Verdict: ACCEPTED
input |
---|
1 2231 100000 16 2 6 8 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 21
Verdict: ACCEPTED
input |
---|
2 1091 2342 100000 1588 4004 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 22
Verdict: TIME LIMIT EXCEEDED
input |
---|
3 144 151 440 100000 ... |
correct output |
---|
168 99 87 262 16 ... |
user output |
---|
(empty) |
Test 23
Verdict: TIME LIMIT EXCEEDED
input |
---|
4 2388 2979 6715 8029 ... |
correct output |
---|
10 52 47 56 77 ... |
user output |
---|
(empty) |
Test 24
Verdict: TIME LIMIT EXCEEDED
input |
---|
5 1371 1946 6455 6889 ... |
correct output |
---|
24 6 15 25 26 ... |
user output |
---|
(empty) |
Test 25
Verdict: TIME LIMIT EXCEEDED
input |
---|
6 1026 1031 4929 5038 ... |
correct output |
---|
18 9 11 12 8 ... |
user output |
---|
(empty) |
Test 26
Verdict: TIME LIMIT EXCEEDED
input |
---|
7 21 44 60 70 ... |
correct output |
---|
16 20 16 20 10 ... |
user output |
---|
(empty) |
Test 27
Verdict: TIME LIMIT EXCEEDED
input |
---|
8 95 627 710 784 ... |
correct output |
---|
6 4 5 5 6 ... |
user output |
---|
(empty) |
Test 28
Verdict: TIME LIMIT EXCEEDED
input |
---|
9 48 209 791 920 ... |
correct output |
---|
3 4 3 6 6 ... |
user output |
---|
(empty) |
Test 29
Verdict: TIME LIMIT EXCEEDED
input |
---|
10 814 1017 1217 3259 ... |
correct output |
---|
4 6 6 4 6 ... |
user output |
---|
(empty) |
Test 30
Verdict: ACCEPTED
input |
---|
2 6748 9615 100000 6956 7730 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 31
Verdict: ACCEPTED
input |
---|
2 2955 5079 100000 5049 3601 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 32
Verdict: ACCEPTED
input |
---|
2 8591 9235 100000 6759 9705 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 33
Verdict: ACCEPTED
input |
---|
2 1847 2965 100000 6674 4858 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 34
Verdict: ACCEPTED
input |
---|
2 2033 7688 100000 4427 4007 ... |
correct output |
---|
-1 -1 -1 -1 -1 ... |
user output |
---|
-1 -1 -1 -1 -1 ... |
Test 35
Verdict: TIME LIMIT EXCEEDED
input |
---|
2 0 1 100000 3190 5237 ... |
correct output |
---|
-1 -1 -1 4232 4266 ... |
user output |
---|
(empty) |
Test 36
Verdict: TIME LIMIT EXCEEDED
input |
---|
2 9999 10000 100000 4761 947 ... |
correct output |
---|
3814 1612 -1 -1 -1 ... |
user output |
---|
(empty) |