#include "bulb.h"
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=3e5+50;
const int mod=1e9+7;
using namespace std;
int n,t,i,j,b,lb[nmax],rb[nmax],rup[nmax],pr[nmax],lst[nmax],nr[nmax],l[nmax],r[nmax],ps[nmax];
void dfs(int x)
{
if(x<0)return;
dfs(l[x]);
if(l[x]==-2 || lb[l[x]])lb[x]=1;
dfs(r[x]);
if(r[x]==-2 || lb[r[x]])rb[x]=1;
}
void up(int x,int p,int k,int ls)
{
if(x<0)return;
nr[x]=k;
lst[x]=ls;
pr[x]=p;
rup[x]=rup[p]|rb[x];
if(p && r[p]>0)ps[x]=1;
ps[x]|=ps[p];
up(l[x],x,k,ls);
up(r[x],x,k+1,x);
if(l[x]>0)rb[x]|=rb[l[x]];
}
int FindWinner(int T,vector<int> L,vector<int> R)
{
n=L.size(),t=T;
for(i=0;i<n;i++)
{
l[i+1]=L[i];
r[i+1]=R[i];
if(l[i+1]>=0)l[i+1]++;
if(r[i+1]>=0)r[i+1]++;
}
dfs(1);
up(1,0,0,0);
for(i=1;i<=n;i++)
{
//cout<<i<<" "<<lb[i]<<" "<<rb[i]<<" "<<rup[i]<<" "<<pr[i]<<" "<<lst[i]<<" "<<nr[i]<<endl;
}
for(i=1;i<=n;i++)
{
if(nr[i]>1)
{
if(!rb[1] && !lb[1])return 1;
}
else if(nr[i]==1)
{
if(r[i]==-2 || lb[r[i]])continue;
if(lb[1])continue;
if(rup[pr[lst[i]]])continue;
if(l[lst[i]]>0 && rb[l[lst[i]]])continue;
//cout<<i<<endl;
return 1;
}
else
{
if(rup[pr[i]])continue;
if(lb[i])continue;
if(r[i]!=-2 && rb[r[i]])continue;
if((r[i]==-2 || lb[r[i]]) && (l[pr[i]]>0 || ps[pr[i]]))continue;
//cout<<i<<endl;
return 1;
}
}
return 0;
}
Compilation message
bulb.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
bulb.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 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 |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 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 |
348 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 |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
348 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 |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 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 |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 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 |
348 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 |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
110 ms |
15992 KB |
Output is correct |
28 |
Correct |
105 ms |
15976 KB |
Output is correct |
29 |
Correct |
111 ms |
15928 KB |
Output is correct |
30 |
Correct |
119 ms |
24184 KB |
Output is correct |
31 |
Correct |
123 ms |
24180 KB |
Output is correct |
32 |
Correct |
112 ms |
15988 KB |
Output is correct |
33 |
Correct |
118 ms |
16348 KB |
Output is correct |
34 |
Correct |
110 ms |
16288 KB |
Output is correct |
35 |
Correct |
111 ms |
16032 KB |
Output is correct |
36 |
Correct |
112 ms |
16004 KB |
Output is correct |
37 |
Correct |
109 ms |
15912 KB |
Output is correct |
38 |
Correct |
110 ms |
16164 KB |
Output is correct |
39 |
Correct |
111 ms |
16232 KB |
Output is correct |
40 |
Correct |
111 ms |
15900 KB |
Output is correct |
41 |
Correct |
108 ms |
15968 KB |
Output is correct |
42 |
Correct |
111 ms |
15532 KB |
Output is correct |
43 |
Correct |
108 ms |
15636 KB |
Output is correct |
44 |
Correct |
110 ms |
15568 KB |
Output is correct |
45 |
Correct |
109 ms |
15556 KB |
Output is correct |
46 |
Correct |
109 ms |
15576 KB |
Output is correct |
47 |
Correct |
109 ms |
17656 KB |
Output is correct |
48 |
Correct |
109 ms |
17688 KB |
Output is correct |
49 |
Correct |
109 ms |
17656 KB |
Output is correct |
50 |
Correct |
107 ms |
17604 KB |
Output is correct |