#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
int count_mushrooms(int n) {
if(n < 220) {
int B = 0;
for(int i = 1; i < n; i++) {
B += use_machine({0, i});
}
return n-B;
}
vector<int> perm;
for(int i = 1; i < n; i++)
perm.push_back(i);
srand(time(0));
vector<int> A, B;
A = {0};
if(use_machine({0,1})) B.push_back(1);
else A.push_back(1);
if(use_machine({0,2})) B.push_back(2);
else A.push_back(2);
if(B.size() > A.size()) swap(A,B);
for(int i = 3; i < n && (A.size()-1)*(A.size()-1) < (n-A.size()-B.size()) && (B.size()-1)*(B.size()-1) < (n-A.size()-B.size()); i+=2) {
vector<int> cur;
cur.push_back(A[0]);
cur.push_back(i);
cur.push_back(A[1]);
if(i+1 < n) cur.push_back(i+1);
// for(auto x: cur) cerr << x << " ";
// cerr << endl;
int res = use_machine(cur);
if(res & 2) B.push_back(i);
else A.push_back(i);
if(i+1 < n) {
if(res & 1) B.push_back(i+1);
else A.push_back(i+1);
}
}
if(B.size() > A.size()) swap(A,B);
int countA = 0;
int countB = 0;
for(int i = A.size()+B.size(); i < n;) {
vector<int> cur;
int j = 0;
for(j = 0; i+j < n && j < A.size(); j++) {
cur.push_back(A[j]);
cur.push_back(i+j);
}
// for(auto x: cur) cerr << x << " ";
// cerr << ": ";
int res = use_machine(cur);
countB += (res+1)/2;
countA += j - ((res+1)/2);
// cerr << i << ": " << A.size() << " " << res << " " << countA << endl;
if(res % 2 == 1) {
B.push_back(cur.back());
countB--;
} else {
A.push_back(cur.back());
countA--;
}
i += j;
if(B.size() > A.size()) {
swap(A,B);
// i--;
}
}
if(A[0] == 0) return A.size()+countA;
else return B.size()+countB;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(j = 0; i+j < n && j < A.size(); j++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
7 ms |
512 KB |
Output is correct |
8 |
Correct |
7 ms |
512 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
9 ms |
512 KB |
Output is correct |
11 |
Partially correct |
7 ms |
512 KB |
Output is partially correct |
12 |
Correct |
7 ms |
512 KB |
Output is correct |
13 |
Correct |
7 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Partially correct |
8 ms |
512 KB |
Output is partially correct |
16 |
Partially correct |
7 ms |
512 KB |
Output is partially correct |
17 |
Correct |
6 ms |
384 KB |
Output is correct |
18 |
Correct |
7 ms |
512 KB |
Output is correct |
19 |
Incorrect |
8 ms |
512 KB |
Answer is not correct. |
20 |
Halted |
0 ms |
0 KB |
- |