#include "bulb.h"
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e5 + 5;
vector < int > Left, Right;
int N;
int FindWinner(int T, std :: vector < int > L, std :: vector < int > R)
{
Left = L;
Right = R;
N = (int)L.size();
int Node = 0;
while(Node >= 0)
Node = Left[Node];
if(Node == -2) /// The leftest bulb is blue;
return 0;
for(int i = 0; i < N; ++i)
{
bool Red = true;
bool Ok = false; /// Daca alegem apasarea unui intrerupator, iar in partea opusa directiei curentului, exista subarbore;
Node = 0;
while(Node >= 0)
{
if(Node == i)
{
if(Left[Node] >= 0)
Ok = true;
}
else
{
if(Right[Node] >= 0)
Ok = true;
}
int Go = (Node == i) ? Left[Node] : Right[Node];
while(Go >= 0)
Go = (Go == i) ? Right[Go] : Left[Go];
if(Go == -2)
{
Red = false;
break;
}
if(Node == i) /// The "i" - th switch is pressed;
Node = Right[Node];
else Node = Left[Node];
}
if(Red && (!Ok || Node == -1)) /// One red bulb is turned on;
return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
76 ms |
8684 KB |
Output is correct |
28 |
Correct |
74 ms |
8588 KB |
Output is correct |
29 |
Correct |
91 ms |
8696 KB |
Output is correct |
30 |
Correct |
80 ms |
8696 KB |
Output is correct |
31 |
Correct |
81 ms |
8696 KB |
Output is correct |
32 |
Correct |
90 ms |
8696 KB |
Output is correct |
33 |
Correct |
78 ms |
8568 KB |
Output is correct |
34 |
Correct |
107 ms |
8568 KB |
Output is correct |
35 |
Correct |
86 ms |
8868 KB |
Output is correct |
36 |
Correct |
106 ms |
9044 KB |
Output is correct |
37 |
Correct |
88 ms |
8840 KB |
Output is correct |
38 |
Correct |
100 ms |
8848 KB |
Output is correct |
39 |
Correct |
78 ms |
8824 KB |
Output is correct |
40 |
Correct |
78 ms |
8824 KB |
Output is correct |
41 |
Correct |
113 ms |
8972 KB |
Output is correct |
42 |
Correct |
95 ms |
9092 KB |
Output is correct |
43 |
Correct |
101 ms |
8984 KB |
Output is correct |
44 |
Correct |
94 ms |
8952 KB |
Output is correct |
45 |
Correct |
106 ms |
8952 KB |
Output is correct |
46 |
Correct |
78 ms |
8824 KB |
Output is correct |
47 |
Correct |
80 ms |
8860 KB |
Output is correct |
48 |
Correct |
85 ms |
8968 KB |
Output is correct |
49 |
Correct |
74 ms |
8924 KB |
Output is correct |
50 |
Correct |
81 ms |
8824 KB |
Output is correct |