# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
556256 |
2022-05-02T16:20:52 Z |
Zanite |
Cave (IOI13_cave) |
C++17 |
|
408 ms |
468 KB |
#include "cave.h"
#include <bits/stdc++.h>
using namespace std;
void exploreCave(int N) {
int toggle[N], correspondence[N];
bool answered[N];
memset(toggle, 0, sizeof(toggle));
memset(correspondence, 0, sizeof(correspondence));
memset(answered, 0, sizeof(answered));
for (int i = 0; i < N; i++) {
// check the correct position of the switch that handles the i-th door
int correctPos = 0;
for (int s = 0; s < N; s++) {
if (!answered[s]) {toggle[s] = 0;}
}
if (tryCombination(toggle) == i) {
for (int s = 0; s < N; s++) {
if (!answered[s]) {toggle[s] = 1;}
}
correctPos = 1;
}
// search which switch connects to the i-th door
deque<int> guesses;
for (int s = 0; s < N; s++) {
if (!answered[s]) {guesses.push_back(s);}
}
while (__builtin_popcount(guesses.size()) != 1) {
guesses.push_back(guesses.back());
}
while (guesses.size() > 1) {
// guess the left half of deque
bool removeLeft = 0;
for (int g = 0; g < (guesses.size() >> 1); g++) {
toggle[guesses[g]] = 1 - correctPos;
}
if (tryCombination(toggle) != i) {
removeLeft = 1;
}
for (int g = 0; g < (guesses.size() >> 1); g++) {
toggle[guesses[g]] = correctPos;
}
if (removeLeft) {
for (int g = 0; g < (guesses.size() >> 1); g++) {
guesses.pop_front();
}
} else {
for (int g = (guesses.size() >> 1); g < guesses.size(); g++) {
guesses.pop_back();
}
}
}
correspondence[guesses[0]] = i;
answered[guesses[0]] = 1;
}
answer(toggle, correspondence);
}
Compilation message
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int g = 0; g < (guesses.size() >> 1); g++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
cave.cpp:44:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int g = 0; g < (guesses.size() >> 1); g++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
cave.cpp:49:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int g = 0; g < (guesses.size() >> 1); g++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
cave.cpp:53:55: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int g = (guesses.size() >> 1); g < guesses.size(); g++) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
305 ms |
340 KB |
too much calls on tryCombination() |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
408 ms |
468 KB |
too much calls on tryCombination() |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
256 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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
256 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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
212 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 |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
93 ms |
360 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
108 ms |
340 KB |
Output is correct |
24 |
Correct |
99 ms |
360 KB |
Output is correct |
25 |
Correct |
101 ms |
352 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
92 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
304 KB |
Output is correct |
30 |
Correct |
88 ms |
384 KB |
Output is correct |
31 |
Correct |
92 ms |
316 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 |
304 KB |
Output is correct |
35 |
Correct |
102 ms |
344 KB |
Output is correct |
36 |
Correct |
99 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
305 ms |
340 KB |
too much calls on tryCombination() |
2 |
Halted |
0 ms |
0 KB |
- |