# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
546227 |
2022-04-06T17:11:36 Z |
LunaMeme |
Cave (IOI13_cave) |
C++14 |
|
433 ms |
468 KB |
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef vector<int> vi;
typedef long long ll;
#define PB push_back
#define MP make_pair
#define FOR(i, x, y) for (int i = x; i < y ; i ++)
/*int N;
vi S, D, C;
void answer(vi A, vi B)
{
for(int i = 0; i < N; i ++)
cout << A[i] << ' ';
cout << '\n';
for(int i = 0; i < N; i ++)
cout << B[i] << ' ';
}
int tryCombination(vi A)
{
for(int door = 0; door < N;door ++)
{
if(A[C[door]] != S[C[door]])
return door;
}
return -1;
}*/
int opp(int d){
if (d == 1)return 0;
return 1;
}
void exploreCave(int N) {
int arr[N];
memset(arr, -1, sizeof arr);
int ans[N];
FOR(i, 0, N){ //door
int temp[N];
FOR(k, 0, N){
if (arr[k] == -1)temp[k] = 0;
else temp[k] = arr[k];
}
int j = tryCombination(temp);
int d = 0; //d is colour of i th switch
if (j <= i && j > -1){
d = 1;
}
//binary search
FOR(k, 0, N){
if (arr[k] == -1)temp[k] = d;
else temp[k] = arr[k];
}
int l = 0, r = N - 1;
while(l < r){
int m = (l + r) / 2;
FOR(k, l, m + 1){
if (arr[k] == -1)
temp[k] = opp(d);
else temp[k] = arr[k];
}
/*FOR(k, 0, N){
cout << temp[k] << ' ';
}
cout << '\n';*/
j = tryCombination(temp);
if (j > i || j == -1) //passes
{
l = m + 1;
}
else{
r = m;
}
FOR(k, 0, N){
if (arr[k] == -1)temp[k] = d;
else temp[k] = arr[k];
}
}
assert(l == r);
//cout << "Door " << i << " connects to switch " << l << '\n';
//assert(arr[l] == -1);
arr[l] = d;
ans[l] = i;
}
answer(arr, ans);
}
/*int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
S.assign(N,0); D.assign(N,0);
C.assign(N,0);
for(int i = 0; i < N; i ++)
cin >> S[i];
for(int i = 0; i < N; i ++)
cin >> D[i];
for(int i = 0; i < N; i ++)
C[D[i]] = i;
exploreCave(N);
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
384 KB |
Output is correct |
2 |
Correct |
251 ms |
460 KB |
Output is correct |
3 |
Correct |
411 ms |
460 KB |
Output is correct |
4 |
Correct |
262 ms |
412 KB |
Output is correct |
5 |
Correct |
419 ms |
340 KB |
Output is correct |
6 |
Correct |
360 ms |
340 KB |
Output is correct |
7 |
Correct |
420 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
358 ms |
428 KB |
Output is correct |
13 |
Correct |
374 ms |
436 KB |
Output is correct |
14 |
Correct |
367 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
433 ms |
400 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
397 ms |
428 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
407 ms |
424 KB |
Output is correct |
7 |
Correct |
379 ms |
340 KB |
Output is correct |
8 |
Correct |
390 ms |
420 KB |
Output is correct |
9 |
Correct |
413 ms |
428 KB |
Output is correct |
10 |
Correct |
413 ms |
444 KB |
Output is correct |
11 |
Correct |
380 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
264 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
264 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
61 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
53 ms |
348 KB |
Output is correct |
24 |
Correct |
55 ms |
348 KB |
Output is correct |
25 |
Correct |
55 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
304 KB |
Output is correct |
28 |
Correct |
58 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
58 ms |
344 KB |
Output is correct |
31 |
Correct |
54 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
54 ms |
340 KB |
Output is correct |
36 |
Correct |
55 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
384 KB |
Output is correct |
2 |
Correct |
251 ms |
460 KB |
Output is correct |
3 |
Correct |
411 ms |
460 KB |
Output is correct |
4 |
Correct |
262 ms |
412 KB |
Output is correct |
5 |
Correct |
419 ms |
340 KB |
Output is correct |
6 |
Correct |
360 ms |
340 KB |
Output is correct |
7 |
Correct |
420 ms |
428 KB |
Output is correct |
8 |
Correct |
0 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
358 ms |
428 KB |
Output is correct |
13 |
Correct |
374 ms |
436 KB |
Output is correct |
14 |
Correct |
367 ms |
440 KB |
Output is correct |
15 |
Correct |
433 ms |
400 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
397 ms |
428 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
407 ms |
424 KB |
Output is correct |
21 |
Correct |
379 ms |
340 KB |
Output is correct |
22 |
Correct |
390 ms |
420 KB |
Output is correct |
23 |
Correct |
413 ms |
428 KB |
Output is correct |
24 |
Correct |
413 ms |
444 KB |
Output is correct |
25 |
Correct |
380 ms |
428 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
300 KB |
Output is correct |
28 |
Correct |
1 ms |
264 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
300 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
61 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
53 ms |
348 KB |
Output is correct |
49 |
Correct |
55 ms |
348 KB |
Output is correct |
50 |
Correct |
55 ms |
348 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
304 KB |
Output is correct |
53 |
Correct |
58 ms |
468 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
58 ms |
344 KB |
Output is correct |
56 |
Correct |
54 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
54 ms |
340 KB |
Output is correct |
61 |
Correct |
55 ms |
348 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
272 ms |
404 KB |
Output is correct |
64 |
Correct |
237 ms |
340 KB |
Output is correct |
65 |
Correct |
418 ms |
424 KB |
Output is correct |
66 |
Correct |
263 ms |
416 KB |
Output is correct |
67 |
Correct |
422 ms |
364 KB |
Output is correct |
68 |
Correct |
370 ms |
424 KB |
Output is correct |
69 |
Correct |
424 ms |
428 KB |
Output is correct |
70 |
Correct |
1 ms |
304 KB |
Output is correct |
71 |
Correct |
1 ms |
300 KB |
Output is correct |
72 |
Correct |
384 ms |
468 KB |
Output is correct |
73 |
Correct |
373 ms |
436 KB |
Output is correct |
74 |
Correct |
380 ms |
428 KB |
Output is correct |
75 |
Correct |
397 ms |
424 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
423 ms |
424 KB |
Output is correct |
79 |
Correct |
396 ms |
428 KB |
Output is correct |
80 |
Correct |
407 ms |
424 KB |
Output is correct |
81 |
Correct |
398 ms |
432 KB |
Output is correct |
82 |
Correct |
396 ms |
340 KB |
Output is correct |
83 |
Correct |
392 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
55 ms |
460 KB |
Output is correct |
86 |
Correct |
375 ms |
428 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |
88 |
Correct |
1 ms |
212 KB |
Output is correct |
89 |
Correct |
54 ms |
360 KB |
Output is correct |
90 |
Correct |
57 ms |
340 KB |
Output is correct |
91 |
Correct |
57 ms |
340 KB |
Output is correct |
92 |
Correct |
392 ms |
376 KB |
Output is correct |
93 |
Correct |
412 ms |
428 KB |
Output is correct |
94 |
Correct |
392 ms |
436 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
372 ms |
428 KB |
Output is correct |
98 |
Correct |
55 ms |
352 KB |
Output is correct |
99 |
Correct |
383 ms |
424 KB |
Output is correct |
100 |
Correct |
1 ms |
212 KB |
Output is correct |
101 |
Correct |
57 ms |
344 KB |
Output is correct |
102 |
Correct |
57 ms |
348 KB |
Output is correct |
103 |
Correct |
361 ms |
420 KB |
Output is correct |
104 |
Correct |
1 ms |
212 KB |
Output is correct |
105 |
Correct |
1 ms |
212 KB |
Output is correct |
106 |
Correct |
1 ms |
212 KB |
Output is correct |
107 |
Correct |
54 ms |
352 KB |
Output is correct |
108 |
Correct |
61 ms |
352 KB |
Output is correct |
109 |
Correct |
384 ms |
428 KB |
Output is correct |
110 |
Correct |
425 ms |
444 KB |
Output is correct |
111 |
Correct |
1 ms |
212 KB |
Output is correct |