#include "bulb.h"
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
int son[300050][2];
int dp[300050][3];
int sz[300050];
void DFS(int n) {
if (n == 300001 || n == 300002) {
dp[n][0] = n - 300001;
dp[n][1] = dp[n][2] = 0;
sz[n] = 0;
return;
}
DFS(son[n][0]);
DFS(son[n][1]);
int L = son[n][0], R = son[n][1];
sz[n] = 1;
sz[n] += sz[L] + sz[R];
dp[n][0] = dp[L][0];
dp[n][1] = dp[L][1];
dp[n][2] = dp[L][2];
if (dp[R][0] == 0) dp[n][1] = 1;
else dp[n][2] = 1;
if (sz[R] != 0 && dp[L][0] == 0) dp[n][1] = 1;
if (sz[R] != 0 && dp[L][0] == 1) dp[n][2] = 1;
}
int FindWinner(int T, std::vector<int> L, std::vector<int> R){
int N = L.size();
for (int i = 0; i < N; i++) {
if (L[i] == -1) L[i] = 300001;
if (L[i] == -2) L[i] = 300002;
if (R[i] == -1) R[i] = 300001;
if (R[i] == -2) R[i] = 300002;
son[i][0] = L[i], son[i][1] = R[i];
}
DFS(0);
if (dp[0][0] == 1) return 0;
int n = 0;
for (int i = 1;; i++) {
int L = son[n][0], R = son[n][1];
if (dp[R][0] == 1) {
if (i + sz[R] == N && !dp[R][2]) return 1;
break;
}
if (!dp[R][2]) return 1;
n = L;
if (n >= 300001) break;
}
int c = 0;
for (int n = 0; n <= 300000; n = son[n][0]) {
int R = son[n][1];
if (dp[R][0] == 1) c++;
}
if (c >= 2) return 0;
if (c == 1) {
for (int n = 0; n <= 300000; n = son[n][0]) {
int R = son[n][1];
if (dp[R][0] != 1) continue;
if (dp[R][1]) return 1;
return 0;
}
}
for (int n = 0; n <= 300000; n = son[n][0]) {
int R = son[n][1];
if (dp[R][1]) return 1;
}
return 0;
}
Compilation message
bulb.cpp:25:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable:4996)
bulb.cpp:26:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/STACK:336777216")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
352 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
352 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 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 |
388 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 |
372 KB |
Output is correct |
21 |
Correct |
2 ms |
372 KB |
Output is correct |
22 |
Correct |
34 ms |
372 KB |
Output is correct |
23 |
Correct |
2 ms |
372 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
352 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 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 |
388 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 |
372 KB |
Output is correct |
21 |
Correct |
2 ms |
372 KB |
Output is correct |
22 |
Correct |
34 ms |
372 KB |
Output is correct |
23 |
Correct |
2 ms |
372 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
100 ms |
14100 KB |
Output is correct |
28 |
Correct |
96 ms |
14864 KB |
Output is correct |
29 |
Correct |
98 ms |
14608 KB |
Output is correct |
30 |
Correct |
98 ms |
18352 KB |
Output is correct |
31 |
Correct |
97 ms |
19520 KB |
Output is correct |
32 |
Correct |
100 ms |
12852 KB |
Output is correct |
33 |
Correct |
99 ms |
14736 KB |
Output is correct |
34 |
Correct |
99 ms |
14932 KB |
Output is correct |
35 |
Correct |
99 ms |
14864 KB |
Output is correct |
36 |
Correct |
101 ms |
14172 KB |
Output is correct |
37 |
Correct |
98 ms |
13852 KB |
Output is correct |
38 |
Correct |
99 ms |
14612 KB |
Output is correct |
39 |
Correct |
98 ms |
14840 KB |
Output is correct |
40 |
Correct |
99 ms |
14256 KB |
Output is correct |
41 |
Correct |
98 ms |
13236 KB |
Output is correct |
42 |
Correct |
99 ms |
14460 KB |
Output is correct |
43 |
Correct |
99 ms |
14872 KB |
Output is correct |
44 |
Correct |
99 ms |
14536 KB |
Output is correct |
45 |
Correct |
99 ms |
13716 KB |
Output is correct |
46 |
Correct |
98 ms |
14844 KB |
Output is correct |
47 |
Correct |
100 ms |
13660 KB |
Output is correct |
48 |
Correct |
100 ms |
14668 KB |
Output is correct |
49 |
Correct |
98 ms |
15648 KB |
Output is correct |
50 |
Correct |
97 ms |
13048 KB |
Output is correct |