#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
int count_mushrooms(int N)
{
const int K = 73;
int add = 0;
vector <int> arr[2];
arr[0] = {0};
for (int i=1;i<N;i++){
if (arr[0].size() > arr[1].size() && arr[0].size() >= K){
vector <int> test;
for (int j=0;j<arr[0].size()&&i+j<N;j++){
test.push_back(arr[0][j]);
test.push_back(i+j);
}
int res = use_machine(test);
add += test.size()>>1;
add -= res&1;
add -= res>>1;
i += arr[0].size()-1;
arr[res&1].push_back(test.back());
}
else if (arr[1].size() >= K){
vector <int> test;
for (int j=0;j<arr[1].size()&&i+j<N;j++){
test.push_back(arr[1][j]);
test.push_back(i+j);
}
int res = use_machine(test);
add += res&1;
add += res>>1;
i += arr[1].size()-1;
arr[res&1^1].push_back(test.back());
}
else if (i+1 < N && arr[0].size() > 1){
int res = use_machine({arr[0][0], i, arr[0][1], i+1});
arr[res>>1&1].push_back(i);
arr[res&1].push_back(++i);
}else if (i+1 < N && arr[1].size() > 1){
int res = use_machine({arr[1][0], i, arr[1][1], i+1});
arr[res>>1&1^1].push_back(i);
arr[res&1^1].push_back(++i);
}
else arr[use_machine({0, i})].push_back(i);
}
return arr[0].size() + add;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int j=0;j<arr[0].size()&&i+j<N;j++){
| ~^~~~~~~~~~~~~~
mushrooms.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int j=0;j<arr[1].size()&&i+j<N;j++){
| ~^~~~~~~~~~~~~~
mushrooms.cpp:37:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
37 | arr[res&1^1].push_back(test.back());
| ~~~^~
mushrooms.cpp:45:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
45 | arr[res>>1&1^1].push_back(i);
| ~~~~~~^~
mushrooms.cpp:46:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
46 | arr[res&1^1].push_back(++i);
| ~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Incorrect |
1 ms |
376 KB |
Answer is not correct. |
6 |
Halted |
0 ms |
0 KB |
- |