/* cerberus97 - Hanit Banga */
#include "bulb.h"
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int N = 3e5 + 10;
vector<int> l, r, turns;
bool p2wins = false;
bool extra = false;
bool t1 = false;
bool del[N], del2[N], on_path[N];
void dfs(int u);
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int n = L.size();
l = L; r = R;
dfs(0);
if (p2wins) {
return false;
}
if (t1) {
for (int i = 0; i < n; ++i) {
if (!on_path[i]) {
del[i] = true;
}
}
}
for (int i = 0; i < n; ++i) {
if (del[i]) {
continue;
} else if (del2[i] and extra) {
continue;
} else {
return true;
}
}
return false;
}
void dfs(int u) {
if (u == -1) {
return;
} else if (u == -2) {
if (turns.empty()) {
p2wins = true;
} else if (turns.size() == 2) {
del[turns[0]] = true;
del[turns[1]] = true;
} else if (turns.size() == 1) {
del2[turns[0]] = true;
t1 = true;
}
} else {
on_path[u] = (turns.empty());
if (!turns.empty()) {
extra = true;
}
dfs(l[u]);
turns.pb(u);
dfs(r[u]);
turns.pop_back();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
292 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
352 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
292 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
352 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
424 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
292 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
352 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
424 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
87 ms |
7796 KB |
Output is correct |
28 |
Correct |
84 ms |
7724 KB |
Output is correct |
29 |
Correct |
89 ms |
7976 KB |
Output is correct |
30 |
Correct |
90 ms |
17272 KB |
Output is correct |
31 |
Correct |
92 ms |
17328 KB |
Output is correct |
32 |
Correct |
94 ms |
7968 KB |
Output is correct |
33 |
Correct |
89 ms |
7712 KB |
Output is correct |
34 |
Correct |
96 ms |
8028 KB |
Output is correct |
35 |
Correct |
90 ms |
7928 KB |
Output is correct |
36 |
Correct |
98 ms |
7928 KB |
Output is correct |
37 |
Correct |
90 ms |
7904 KB |
Output is correct |
38 |
Correct |
90 ms |
8004 KB |
Output is correct |
39 |
Correct |
95 ms |
7716 KB |
Output is correct |
40 |
Correct |
93 ms |
7680 KB |
Output is correct |
41 |
Correct |
97 ms |
7944 KB |
Output is correct |
42 |
Correct |
121 ms |
8548 KB |
Output is correct |
43 |
Correct |
98 ms |
8796 KB |
Output is correct |
44 |
Correct |
96 ms |
8452 KB |
Output is correct |
45 |
Correct |
89 ms |
8412 KB |
Output is correct |
46 |
Correct |
90 ms |
8428 KB |
Output is correct |
47 |
Correct |
90 ms |
10872 KB |
Output is correct |
48 |
Correct |
90 ms |
10648 KB |
Output is correct |
49 |
Correct |
91 ms |
11356 KB |
Output is correct |
50 |
Correct |
90 ms |
9976 KB |
Output is correct |