Task: | Mobiles |
Sender: | Yytsi |
Submission time: | 2019-03-07 16:06:53 +0200 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | WRONG ANSWER | 0.01 s | details |
#7 | WRONG ANSWER | 0.02 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.02 s | details |
#10 | ACCEPTED | 0.01 s | details |
#11 | ACCEPTED | 0.03 s | details |
#12 | ACCEPTED | 0.01 s | details |
#13 | WRONG ANSWER | 0.04 s | details |
#14 | ACCEPTED | 0.02 s | details |
#15 | ACCEPTED | 0.02 s | details |
#16 | WRONG ANSWER | 0.02 s | details |
#17 | ACCEPTED | 0.03 s | details |
#18 | ACCEPTED | 0.02 s | details |
#19 | ACCEPTED | 0.03 s | details |
#20 | ACCEPTED | 0.02 s | details |
#21 | ACCEPTED | 0.01 s | details |
#22 | ACCEPTED | 0.02 s | details |
#23 | ACCEPTED | 0.02 s | details |
#24 | ACCEPTED | 0.02 s | details |
#25 | ACCEPTED | 0.06 s | details |
#26 | ACCEPTED | 0.02 s | details |
#27 | WRONG ANSWER | 0.02 s | details |
#28 | ACCEPTED | 0.01 s | details |
#29 | ACCEPTED | 0.02 s | details |
#30 | WRONG ANSWER | 0.02 s | details |
#31 | WRONG ANSWER | 0.02 s | details |
#32 | ACCEPTED | 0.04 s | details |
#33 | WRONG ANSWER | 0.05 s | details |
#34 | ACCEPTED | 0.05 s | details |
#35 | WRONG ANSWER | 0.05 s | details |
#36 | WRONG ANSWER | 0.05 s | details |
#37 | ACCEPTED | 0.03 s | details |
#38 | WRONG ANSWER | 0.05 s | details |
#39 | WRONG ANSWER | 0.05 s | details |
#40 | WRONG ANSWER | 0.04 s | details |
#41 | WRONG ANSWER | 0.04 s | details |
#42 | WRONG ANSWER | 0.04 s | details |
Compiler report
input/code.cpp: In function 'void f(int, int)': input/code.cpp:34:12: warning: array subscript is below array bounds [-Warray-bounds] minimax[l].F = d + 1; ~~~~~~~~~^ input/code.cpp:35:12: warning: array subscript is below array bounds [-Warray-bounds] minimax[l].S = d + 1; ~~~~~~~~~^ input/code.cpp:42:12: warning: array subscript is below array bounds [-Warray-bounds] minimax[r].F = d + 1; ~~~~~~~~~^ input/code.cpp:43:12: warning: array subscript is below array bounds [-Warray-bounds] minimax[r].S = d + 1; ~~~~~~~~~^
Code
// Tässä on varmaan 5x pikkuvirhettä ja korjattavaa #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define IO ios_base::sync_with_stdio(0); cin.tie(0) #define F first #define S second #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define N 101010 int n; bool star[N]; pii minimax[N]; pii children[N]; void qaq() { cout<<"-1\n"; exit(0); } int res = 0; void f(int x, int d) { int l = children[x].F, r = children[x].S; int lmin = 999, lmax = 0, rmin = 999, rmax = 0; if (l == -1) { int l_depth = d + 1; lmin = l_depth; lmax = l_depth; minimax[l].F = d + 1; minimax[l].S = d + 1; } else f(l, d+1); if (r == -1) { int r_depth = d + 1; rmin = r_depth; rmax = r_depth; minimax[r].F = d + 1; minimax[r].S = d + 1; } else f(r, d+1); minimax[x] = {min(minimax[l].F, lmin), max(minimax[r].S, rmax)}; lmin = min(lmin, minimax[l].F); lmax = max(lmax, minimax[l].S); rmin = min(rmin, minimax[r].F); rmax = max(rmax, minimax[r].S); //cout<<"at "<<x<<" {"<<lmin<<","<<lmax<<"} {"<<rmin<<","<<rmax<<"}\n"; if (abs(lmin - lmax) > 1) { qaq(); } if (abs(rmin - rmax) > 1) { qaq(); } if (abs(lmin - rmax) > 1) { qaq(); } if (abs(lmin - rmin) > 1) { qaq(); } if (abs(lmax - rmin) > 1) { qaq(); } if (abs(lmax - rmax) > 1) { qaq(); } bool left_diff = abs(lmin - lmax) > 0; bool right_diff = abs(rmin - rmax) > 0; // 1. if (left_diff && right_diff) qaq(); // 6. if (!left_diff && !right_diff) return; if (!right_diff) { // 2. if ((lmax == rmax) && (lmin < rmax)) { res++; return; } // 4. if (!left_diff) { if (lmax > rmin) return; // 5. if (lmin < rmax) { res++; return; } } } if (!left_diff) { // 3. if ((rmax == lmax) && (rmin < rmax)) return; } } int main() { IO; cin>>n; FOR(x,1,n+1) { int l, r; cin>>l>>r; children[x] = {l, r}; } f(1,0); cout<<res<<"\n"; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 -1 -1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 2
Verdict: ACCEPTED
input |
---|
2 2 -1 -1 -1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 3
Verdict: ACCEPTED
input |
---|
2 -1 2 -1 -1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 4
Verdict: ACCEPTED
input |
---|
4 2 3 4 -1 -1 -1 -1 -1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 5
Verdict: ACCEPTED
input |
---|
4 2 3 -1 4 -1 -1 -1 -1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 6
Verdict: WRONG ANSWER
input |
---|
4 2 3 -1 -1 4 -1 -1 -1 |
correct output |
---|
1 |
user output |
---|
0 |
Test 7
Verdict: WRONG ANSWER
input |
---|
4 2 3 -1 -1 -1 4 -1 -1 |
correct output |
---|
2 |
user output |
---|
1 |
Test 8
Verdict: ACCEPTED
input |
---|
5 2 3 4 5 -1 -1 -1 -1 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 9
Verdict: ACCEPTED
input |
---|
5 2 3 4 -1 5 -1 -1 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 10
Verdict: ACCEPTED
input |
---|
5 2 3 4 -1 -1 5 -1 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 11
Verdict: ACCEPTED
input |
---|
5 2 3 -1 4 5 -1 -1 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 12
Verdict: ACCEPTED
input |
---|
5 2 3 -1 4 -1 5 -1 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 13
Verdict: WRONG ANSWER
input |
---|
5 2 3 -1 -1 4 5 -1 -1 ... |
correct output |
---|
1 |
user output |
---|
0 |
Test 14
Verdict: ACCEPTED
input |
---|
6 2 3 4 5 6 -1 -1 -1 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 15
Verdict: ACCEPTED
input |
---|
6 2 3 4 5 -1 6 -1 -1 ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 16
Verdict: WRONG ANSWER
input |
---|
6 2 3 4 -1 5 6 -1 -1 ... |
correct output |
---|
1 |
user output |
---|
0 |
Test 17
Verdict: ACCEPTED
input |
---|
6 2 3 -1 4 5 6 -1 -1 ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 18
Verdict: ACCEPTED
input |
---|
19 2 3 6 5 4 7 -1 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 19
Verdict: ACCEPTED
input |
---|
9 3 2 4 5 -1 -1 6 9 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 20
Verdict: ACCEPTED
input |
---|
4 -1 2 3 4 -1 -1 -1 -1 |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 21
Verdict: ACCEPTED
input |
---|
12 3 2 4 5 -1 6 7 9 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 22
Verdict: ACCEPTED
input |
---|
10 3 2 7 5 4 6 8 10 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 23
Verdict: ACCEPTED
input |
---|
1000 2 -1 -1 3 4 -1 5 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 24
Verdict: ACCEPTED
input |
---|
10000 2 -1 -1 3 4 -1 5 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 25
Verdict: ACCEPTED
input |
---|
100000 2 -1 -1 3 4 -1 5 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 26
Verdict: ACCEPTED
input |
---|
10 2 3 6 5 7 4 -1 -1 ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 27
Verdict: WRONG ANSWER
input |
---|
18 2 3 7 6 5 4 11 9 ... |
correct output |
---|
3 |
user output |
---|
1 |
Test 28
Verdict: ACCEPTED
input |
---|
13 3 2 4 5 7 6 -1 -1 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 29
Verdict: ACCEPTED
input |
---|
660 3 2 5 6 7 4 10 8 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 30
Verdict: WRONG ANSWER
input |
---|
1250 2 3 6 7 5 4 10 14 ... |
correct output |
---|
7 |
user output |
---|
2 |
Test 31
Verdict: WRONG ANSWER
input |
---|
5000 2 3 6 7 5 4 11 14 ... |
correct output |
---|
4 |
user output |
---|
0 |
Test 32
Verdict: ACCEPTED
input |
---|
32767 2 3 5 4 7 6 13 14 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 33
Verdict: WRONG ANSWER
input |
---|
100000 2 3 5 7 4 6 15 14 ... |
correct output |
---|
7 |
user output |
---|
0 |
Test 34
Verdict: ACCEPTED
input |
---|
98348 3 2 7 5 6 4 10 8 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 35
Verdict: WRONG ANSWER
input |
---|
100000 2 3 5 7 4 6 15 14 ... |
correct output |
---|
7 |
user output |
---|
0 |
Test 36
Verdict: WRONG ANSWER
input |
---|
99999 3 2 7 5 6 4 10 8 ... |
correct output |
---|
5 |
user output |
---|
0 |
Test 37
Verdict: ACCEPTED
input |
---|
98348 3 2 7 5 6 4 10 8 ... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 38
Verdict: WRONG ANSWER
input |
---|
98303 3 2 5 4 7 6 9 8 ... |
correct output |
---|
1 |
user output |
---|
0 |
Test 39
Verdict: WRONG ANSWER
input |
---|
98304 3 2 5 4 7 6 9 8 ... |
correct output |
---|
16 |
user output |
---|
2 |
Test 40
Verdict: WRONG ANSWER
input |
---|
99989 3 2 5 4 7 6 9 8 ... |
correct output |
---|
15 |
user output |
---|
6 |
Test 41
Verdict: WRONG ANSWER
input |
---|
99989 2 3 4 5 6 7 8 9 ... |
correct output |
---|
15 |
user output |
---|
6 |
Test 42
Verdict: WRONG ANSWER
input |
---|
100000 3 2 5 4 7 6 9 8 ... |
correct output |
---|
16 |
user output |
---|
6 |