#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int repeticoes = 80;
int qtd_min = 180;
vector<int> color[2];
int count_mushrooms(int N) {
qtd_min = min(qtd_min, N);
int cnt[2]{};
color[0] = {0};
vector<int> unknown(N-1);
iota(unknown.begin(), unknown.end(), 1);
bool foi = 0;
while(unknown.size()) {
int usar = color[1].size() > color[0].size(); // escolho o grupo que tem mais gente pra usar
int sz = color[usar].size();
if(sz == 2 && !foi) {
foi = 1;
for(; (max(color[0].size(), color[1].size()) < 3 || min(color[0].size(), color[1].size()) < 2)
&& color[0].size() + color[1].size() < qtd_min && unknown.size() > 2;) {
vector<int> qr;
for(int i = 0; i < 2; i++, unknown.pop_back())
qr.push_back(color[usar][i]), qr.push_back(unknown.back());
int resp = use_machine(qr);
color[usar ^ (resp&1)].push_back(qr.back());
resp >>= 1;
color[usar ^ (resp&1)].push_back(qr[1]);
}
usar = color[1].size() > color[0].size(); // escolho o grupo que tem mais gente pra usar
sz = color[usar].size();
for(; color[0].size() + color[1].size() < qtd_min && unknown.size() >= 5;) {
vector<int> qr;
for(int i = 0; i < 3; i++, unknown.pop_back())
qr.push_back(color[usar][i]), qr.push_back(unknown.back());
int resp = use_machine(qr);
color[usar ^ (resp&1)].push_back(qr.back());
qr.pop_back(), qr.pop_back();
resp >>= 1;
if(resp&1) {
// os dois são diferentes
int x1 = qr[1], x2 = qr[3];
int uk1 = unknown.back(); unknown.pop_back();
int uk2 = unknown.back(); unknown.pop_back();
qr.clear();
qr = {color[usar^1][0], x1, color[usar^1][1], color[usar][0], x2, color[usar][1], uk1, color[usar][2], uk2};
int resp = use_machine(qr);
resp--; // removo a ligacao obrigatoria entre color[usar^1][1] e color[usar][0]
color[usar^(resp&1)].push_back(uk2);
resp>>=1;
color[usar^(resp&1)].push_back(uk1);
resp>>=1;
color[usar^1^(resp&1)].push_back(x1);
color[usar^(resp&1)].push_back(x2);
} else {
color[usar^(resp==2)].push_back(qr[1]), color[usar^(resp==2)].push_back(qr[3]);
}
}
continue;
}
vector<int> qr;
for(int i = 0; i < sz && unknown.size(); i++, unknown.pop_back())
qr.push_back(color[usar][i]), qr.push_back(unknown.back());
int resp = use_machine(qr);
color[usar ^ (resp&1)].push_back(qr.back());
cnt[usar^1] += resp/2;
cnt[usar] += (qr.size() / 2 - 1) - resp/2;
}
return cnt[0] + color[0].size();
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:26:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
26 | && color[0].size() + color[1].size() < qtd_min && unknown.size() > 2;) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
mushrooms.cpp:42:44: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | for(; color[0].size() + color[1].size() < qtd_min && unknown.size() >= 5;) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
6 ms |
392 KB |
Output is correct |
8 |
Correct |
6 ms |
336 KB |
Output is correct |
9 |
Correct |
5 ms |
336 KB |
Output is correct |
10 |
Correct |
6 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
392 KB |
Output is correct |
12 |
Correct |
9 ms |
388 KB |
Output is correct |
13 |
Correct |
7 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
480 KB |
Output is correct |
15 |
Correct |
7 ms |
336 KB |
Output is correct |
16 |
Correct |
7 ms |
400 KB |
Output is correct |
17 |
Correct |
5 ms |
356 KB |
Output is correct |
18 |
Correct |
5 ms |
336 KB |
Output is correct |
19 |
Correct |
6 ms |
404 KB |
Output is correct |
20 |
Correct |
6 ms |
392 KB |
Output is correct |
21 |
Correct |
6 ms |
336 KB |
Output is correct |
22 |
Correct |
7 ms |
408 KB |
Output is correct |
23 |
Correct |
6 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
372 KB |
Output is correct |
25 |
Correct |
9 ms |
396 KB |
Output is correct |
26 |
Correct |
10 ms |
396 KB |
Output is correct |
27 |
Correct |
8 ms |
408 KB |
Output is correct |
28 |
Correct |
7 ms |
336 KB |
Output is correct |
29 |
Correct |
8 ms |
404 KB |
Output is correct |
30 |
Correct |
8 ms |
400 KB |
Output is correct |
31 |
Correct |
7 ms |
404 KB |
Output is correct |
32 |
Correct |
7 ms |
400 KB |
Output is correct |
33 |
Correct |
6 ms |
388 KB |
Output is correct |
34 |
Correct |
6 ms |
392 KB |
Output is correct |
35 |
Partially correct |
6 ms |
336 KB |
Output is partially correct |
36 |
Correct |
6 ms |
392 KB |
Output is correct |
37 |
Correct |
6 ms |
404 KB |
Output is correct |
38 |
Correct |
6 ms |
388 KB |
Output is correct |
39 |
Partially correct |
7 ms |
396 KB |
Output is partially correct |
40 |
Correct |
7 ms |
404 KB |
Output is correct |
41 |
Correct |
7 ms |
392 KB |
Output is correct |
42 |
Correct |
10 ms |
336 KB |
Output is correct |
43 |
Correct |
8 ms |
336 KB |
Output is correct |
44 |
Partially correct |
6 ms |
396 KB |
Output is partially correct |
45 |
Partially correct |
6 ms |
336 KB |
Output is partially correct |
46 |
Correct |
6 ms |
408 KB |
Output is correct |
47 |
Correct |
8 ms |
336 KB |
Output is correct |
48 |
Correct |
8 ms |
404 KB |
Output is correct |
49 |
Correct |
6 ms |
336 KB |
Output is correct |
50 |
Correct |
6 ms |
388 KB |
Output is correct |
51 |
Partially correct |
8 ms |
336 KB |
Output is partially correct |
52 |
Correct |
6 ms |
336 KB |
Output is correct |
53 |
Correct |
9 ms |
388 KB |
Output is correct |
54 |
Correct |
7 ms |
336 KB |
Output is correct |
55 |
Correct |
6 ms |
384 KB |
Output is correct |
56 |
Correct |
6 ms |
336 KB |
Output is correct |
57 |
Correct |
8 ms |
400 KB |
Output is correct |
58 |
Correct |
6 ms |
336 KB |
Output is correct |
59 |
Correct |
7 ms |
336 KB |
Output is correct |
60 |
Correct |
8 ms |
336 KB |
Output is correct |
61 |
Correct |
8 ms |
408 KB |
Output is correct |
62 |
Correct |
0 ms |
208 KB |
Output is correct |
63 |
Correct |
0 ms |
208 KB |
Output is correct |
64 |
Correct |
1 ms |
208 KB |
Output is correct |
65 |
Correct |
0 ms |
208 KB |
Output is correct |
66 |
Correct |
0 ms |
208 KB |
Output is correct |
67 |
Correct |
0 ms |
208 KB |
Output is correct |
68 |
Correct |
0 ms |
208 KB |
Output is correct |
69 |
Correct |
0 ms |
208 KB |
Output is correct |
70 |
Correct |
0 ms |
208 KB |
Output is correct |
71 |
Correct |
0 ms |
208 KB |
Output is correct |
72 |
Correct |
0 ms |
208 KB |
Output is correct |
73 |
Correct |
0 ms |
208 KB |
Output is correct |
74 |
Correct |
1 ms |
208 KB |
Output is correct |
75 |
Correct |
0 ms |
208 KB |
Output is correct |
76 |
Correct |
1 ms |
208 KB |
Output is correct |
77 |
Correct |
0 ms |
208 KB |
Output is correct |
78 |
Correct |
1 ms |
208 KB |
Output is correct |
79 |
Correct |
1 ms |
208 KB |
Output is correct |
80 |
Correct |
1 ms |
208 KB |
Output is correct |
81 |
Correct |
1 ms |
208 KB |
Output is correct |
82 |
Correct |
1 ms |
208 KB |
Output is correct |
83 |
Correct |
0 ms |
208 KB |
Output is correct |
84 |
Correct |
0 ms |
208 KB |
Output is correct |
85 |
Correct |
1 ms |
208 KB |
Output is correct |
86 |
Correct |
0 ms |
208 KB |
Output is correct |
87 |
Correct |
0 ms |
208 KB |
Output is correct |
88 |
Correct |
0 ms |
208 KB |
Output is correct |
89 |
Correct |
0 ms |
208 KB |
Output is correct |
90 |
Correct |
0 ms |
208 KB |
Output is correct |
91 |
Correct |
0 ms |
208 KB |
Output is correct |