#include "mushrooms.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int count_mushrooms(int n) {
vector<int> A(n);
for (int i = 0; i < n; i++) {
A[i] = i + 1;
}
random_shuffle(A.begin() + 1, A.end());
int ans = 1;
int a = 1, b = 0, fir, sec;
int cur = use_machine({1, A[1]});
if (n == 2)
return ans + !cur;
int cur2 = use_machine({1, A[2]});
if (!cur || !cur2) {
ans += 1 + (!cur & !cur2);
fir = 1;
if (!cur) {
sec = A[1];
}
else {
sec = A[2];
}
for (int i = 3; i < n; i += 3) {
if (n - i == 1) {
int diff = use_machine({fir, A[i]});
ans += 1 - diff;
}
else if (n - i == 2) {
int diff = use_machine({fir, A[i]});
ans += 2 - diff;
}
else {
int diff = use_machine({A[i], fir, A[i+1], sec, A[i+2]});
if (diff <= 1) {
ans += 3 - diff;
}
else if(diff >= 3) {
ans += 4 - diff;
}
else {
int diff2 = use_machine({fir, A[i + 1]});
if (diff2) {
ans += 2;
}
else {
ans++;
}
}
}
}
}
else {
fir = A[1], sec = A[2];
for (int i = 3; i < n; i += 3) {
if (n - i == 1) {
int diff = use_machine({fir, A[i]});
ans += diff;
}
else if (n - i == 2) {
int diff = use_machine({fir, A[i]});
ans += diff;
}
else {
int diff = use_machine({A[i], fir, A[i+1], sec, A[i+2]});
if (diff <= 1) {
ans += diff;
}
else if(diff >= 3) {
ans += diff - 1;
}
else {
int diff2 = use_machine({fir, A[i + 1]});
if (diff2) {
ans ++;
}
else {
ans += 2;
}
}
}
}
}
return ans;
}
Compilation message
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:21:9: warning: unused variable 'a' [-Wunused-variable]
21 | int a = 1, b = 0, fir, sec;
| ^
mushrooms.cpp:21:16: warning: unused variable 'b' [-Wunused-variable]
21 | int a = 1, b = 0, fir, sec;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
592 KB |
Invalid value 3 in the query array. |
2 |
Halted |
0 ms |
0 KB |
- |