#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)
#include "mushrooms.h"
//vector<int> B;
//
//int use_machine(vector<int> X){
// int res = 0;
// for (int i = 1; i < X.size(); i++) {
// if (B[X[i] - 1] != B[X[i - 1] - 1]) {
// res++;
// }
// }
// return res;
//}
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 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({A[i], fir, A[i + 1]});
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({A[i], fir, A[i + 1]});
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;
}
//int main() {
// int n;
// cin >> n;
//
// B.resize(n);
//
// for (int i = 0; i < n; i++) {
// cin >> B[i];
// }
//
// cout << count_mushrooms(n);
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Invalid value 3 in the query array. |
2 |
Halted |
0 ms |
0 KB |
- |