# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1075537 |
2024-08-26T07:31:12 Z |
mc061 |
Cave (IOI13_cave) |
C++17 |
|
511 ms |
956 KB |
#pragma once
#include <bits/stdc++.h>
#include "cave.h"
using namespace std;
const int sz = 5000;
int ck[sz];
int idx_for[sz];
int ans[sz];
int st[sz];
int sta_for[sz];
int tryCombination(int S[]);
int tryC(const vector<int>& state, int cur_test, int switch_pos) {
for (int i = 0; i < sz; ++i) ck[i] = switch_pos^1;
for (int i = 0; i < cur_test; ++i) {
ck[idx_for[i]] = sta_for[i];
}
for (int i = 0; i < state.size(); ++i) {
ck[state[i]] = switch_pos;
}
return tryCombination(ck);
}
void answer(int S[], int D[]);
pair<int, int> solve(int idx, const vector<int>& candidates, int open_state) {
if (candidates.size() == 1) return {candidates.front(), open_state};
vector<int> left, right;
for (int i = 0; i < candidates.size()/2; ++i) {
left.push_back(candidates[i]);
}
for (int i = candidates.size()/2; i < candidates.size(); ++i) {
right.push_back(candidates[i]);
}
int v = tryC(left, idx, open_state);
if (v != idx) return solve(idx, left, open_state);
return solve(idx, right, open_state);
}
//return switch responsible for door idx and state
pair<int, int> get_ans(int idx, vector<int> candidates) {
int v = tryC(candidates, idx, 1);
int open_state = 0;
if (v != idx) open_state = 1;
return solve(idx, candidates, open_state);
}
void exploreCave(int N) {
vector<int> candidates;
for (int i = 0; i < N; ++i) {
candidates.push_back(i);
}
for (int i = 0; i < N; ++i) {
auto [idx, state] = get_ans(i, candidates);
// cerr << idx << "->" << i << "\n";
idx_for[i] = idx;
sta_for[i] = state;
ans[idx_for[i]] = i;
st[idx_for[i]] = state;
candidates.erase(find(candidates.begin(), candidates.end(), idx));
}
// for (int i = 0; i < N; ++i) {
// cout << ans[i] << " ";
// }
// cout << "\n";
// for (int i = 0; i < N; ++i) {
// cout << st[i] << " ";
// }
// cout << "\n";
answer(st, ans);
}
Compilation message
cave.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
cave.cpp: In function 'int tryC(const std::vector<int>&, int, int)':
cave.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < state.size(); ++i) {
| ~~^~~~~~~~~~~~~~
cave.cpp: In function 'std::pair<int, int> solve(int, const std::vector<int>&, int)':
cave.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < candidates.size()/2; ++i) {
| ~~^~~~~~~~~~~~~~~~~~~~~
cave.cpp:34:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = candidates.size()/2; i < candidates.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
620 KB |
Output is correct |
2 |
Correct |
314 ms |
604 KB |
Output is correct |
3 |
Correct |
420 ms |
604 KB |
Output is correct |
4 |
Correct |
308 ms |
604 KB |
Output is correct |
5 |
Correct |
411 ms |
660 KB |
Output is correct |
6 |
Correct |
416 ms |
648 KB |
Output is correct |
7 |
Correct |
404 ms |
652 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
397 ms |
664 KB |
Output is correct |
13 |
Correct |
436 ms |
700 KB |
Output is correct |
14 |
Correct |
406 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
426 ms |
660 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
417 ms |
676 KB |
Output is correct |
7 |
Correct |
433 ms |
512 KB |
Output is correct |
8 |
Correct |
426 ms |
676 KB |
Output is correct |
9 |
Correct |
431 ms |
764 KB |
Output is correct |
10 |
Correct |
450 ms |
708 KB |
Output is correct |
11 |
Correct |
442 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
496 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
348 KB |
Output is correct |
9 |
Correct |
2 ms |
496 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
109 ms |
548 KB |
Output is correct |
21 |
Correct |
4 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
348 KB |
Output is correct |
23 |
Correct |
110 ms |
556 KB |
Output is correct |
24 |
Correct |
107 ms |
348 KB |
Output is correct |
25 |
Correct |
112 ms |
556 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
110 ms |
560 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
110 ms |
552 KB |
Output is correct |
31 |
Correct |
111 ms |
552 KB |
Output is correct |
32 |
Correct |
3 ms |
344 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
105 ms |
556 KB |
Output is correct |
36 |
Correct |
105 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
620 KB |
Output is correct |
2 |
Correct |
314 ms |
604 KB |
Output is correct |
3 |
Correct |
420 ms |
604 KB |
Output is correct |
4 |
Correct |
308 ms |
604 KB |
Output is correct |
5 |
Correct |
411 ms |
660 KB |
Output is correct |
6 |
Correct |
416 ms |
648 KB |
Output is correct |
7 |
Correct |
404 ms |
652 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
397 ms |
664 KB |
Output is correct |
13 |
Correct |
436 ms |
700 KB |
Output is correct |
14 |
Correct |
406 ms |
600 KB |
Output is correct |
15 |
Correct |
410 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
426 ms |
660 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
417 ms |
676 KB |
Output is correct |
21 |
Correct |
433 ms |
512 KB |
Output is correct |
22 |
Correct |
426 ms |
676 KB |
Output is correct |
23 |
Correct |
431 ms |
764 KB |
Output is correct |
24 |
Correct |
450 ms |
708 KB |
Output is correct |
25 |
Correct |
442 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
440 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
496 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
348 KB |
Output is correct |
45 |
Correct |
109 ms |
548 KB |
Output is correct |
46 |
Correct |
4 ms |
348 KB |
Output is correct |
47 |
Correct |
5 ms |
348 KB |
Output is correct |
48 |
Correct |
110 ms |
556 KB |
Output is correct |
49 |
Correct |
107 ms |
348 KB |
Output is correct |
50 |
Correct |
112 ms |
556 KB |
Output is correct |
51 |
Correct |
3 ms |
344 KB |
Output is correct |
52 |
Correct |
3 ms |
348 KB |
Output is correct |
53 |
Correct |
110 ms |
560 KB |
Output is correct |
54 |
Correct |
2 ms |
348 KB |
Output is correct |
55 |
Correct |
110 ms |
552 KB |
Output is correct |
56 |
Correct |
111 ms |
552 KB |
Output is correct |
57 |
Correct |
3 ms |
344 KB |
Output is correct |
58 |
Correct |
3 ms |
348 KB |
Output is correct |
59 |
Correct |
3 ms |
348 KB |
Output is correct |
60 |
Correct |
105 ms |
556 KB |
Output is correct |
61 |
Correct |
105 ms |
344 KB |
Output is correct |
62 |
Correct |
1 ms |
344 KB |
Output is correct |
63 |
Correct |
290 ms |
624 KB |
Output is correct |
64 |
Correct |
297 ms |
852 KB |
Output is correct |
65 |
Correct |
412 ms |
604 KB |
Output is correct |
66 |
Correct |
314 ms |
600 KB |
Output is correct |
67 |
Correct |
427 ms |
604 KB |
Output is correct |
68 |
Correct |
401 ms |
852 KB |
Output is correct |
69 |
Correct |
406 ms |
600 KB |
Output is correct |
70 |
Correct |
1 ms |
344 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
403 ms |
504 KB |
Output is correct |
73 |
Correct |
405 ms |
668 KB |
Output is correct |
74 |
Correct |
396 ms |
648 KB |
Output is correct |
75 |
Correct |
416 ms |
856 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
423 ms |
668 KB |
Output is correct |
79 |
Correct |
433 ms |
656 KB |
Output is correct |
80 |
Correct |
449 ms |
696 KB |
Output is correct |
81 |
Correct |
435 ms |
604 KB |
Output is correct |
82 |
Correct |
440 ms |
604 KB |
Output is correct |
83 |
Correct |
440 ms |
600 KB |
Output is correct |
84 |
Correct |
3 ms |
344 KB |
Output is correct |
85 |
Correct |
110 ms |
548 KB |
Output is correct |
86 |
Correct |
457 ms |
852 KB |
Output is correct |
87 |
Correct |
3 ms |
348 KB |
Output is correct |
88 |
Correct |
2 ms |
496 KB |
Output is correct |
89 |
Correct |
113 ms |
568 KB |
Output is correct |
90 |
Correct |
107 ms |
564 KB |
Output is correct |
91 |
Correct |
107 ms |
452 KB |
Output is correct |
92 |
Correct |
427 ms |
600 KB |
Output is correct |
93 |
Correct |
433 ms |
604 KB |
Output is correct |
94 |
Correct |
428 ms |
956 KB |
Output is correct |
95 |
Correct |
3 ms |
348 KB |
Output is correct |
96 |
Correct |
3 ms |
488 KB |
Output is correct |
97 |
Correct |
417 ms |
676 KB |
Output is correct |
98 |
Correct |
115 ms |
348 KB |
Output is correct |
99 |
Correct |
444 ms |
660 KB |
Output is correct |
100 |
Correct |
3 ms |
344 KB |
Output is correct |
101 |
Correct |
110 ms |
536 KB |
Output is correct |
102 |
Correct |
136 ms |
348 KB |
Output is correct |
103 |
Correct |
511 ms |
676 KB |
Output is correct |
104 |
Correct |
3 ms |
344 KB |
Output is correct |
105 |
Correct |
3 ms |
344 KB |
Output is correct |
106 |
Correct |
2 ms |
348 KB |
Output is correct |
107 |
Correct |
105 ms |
556 KB |
Output is correct |
108 |
Correct |
105 ms |
552 KB |
Output is correct |
109 |
Correct |
437 ms |
684 KB |
Output is correct |
110 |
Correct |
418 ms |
940 KB |
Output is correct |
111 |
Correct |
1 ms |
344 KB |
Output is correct |