# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759982 | raysh07 | Counting Mushrooms (IOI20_mushrooms) | C++17 | 7 ms | 460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;
// const int N = 101;
// int ac[N];
// int use_machine(vector <int> a){
// int ans = 0;
// for (int i = 1; i < a.size(); i++){
// ans += ac[a[i]] != ac[a[i - 1]];
// }
// return ans;
// }
int count_mushrooms(int n) {
vector <int> a, b;
a.push_back(0);
int p = 1;
int ans = 0;
const int C = 126;
int moves = 0;
while (p < n){
if (p != (n - 1) && (a.size() + b.size()) <= C && max(a.size(), b.size()) >= 2){
if (a.size() >= 2) {
int c = use_machine({a[0], p, a[1], p + 1});
moves++;
if (c & 1) b.push_back(p + 1);
else a.push_back(p + 1);
if (c >= 2) b.push_back(p);
else a.push_back(p);
} else {
int c = use_machine({b[0], p, b[1], p + 1});
moves++;
if (c & 1) a.push_back(p + 1);
else b.push_back(p + 1);
if (c >= 2) a.push_back(p);
else b.push_back(p);
}
p += 2;
continue;
}
// cout << "PRINTING " << p << " ";
// for (auto x : a) cout << x << " ";
// cout << "\n";
if (a.size() > b.size()){
int g = a.size();
g = min(g, n - p);
vector <int> m;
for (int i = 0; i < g; i++){
m.push_back(p + i);
m.push_back(a[i]);
}
int c = use_machine(m);
if (c & 1) b.push_back(p), c--;
else a.push_back(p);
moves++;
// cout << g << " " << c/2 << "\n";
ans += g - 1 - (c/2);
p += g;
} else {
int g = b.size();
g = min(g, n - p);
vector <int> m;
for (int i = 0; i < g; i++){
m.push_back(p + i);
m.push_back(b[i]);
}
int c = use_machine(m);
if (c & 1) a.push_back(p), c--;
else b.push_back(p);
moves++;
ans += c/2;
p += g;
}
}
return ans + a.size();
}
// int main(){
// int n; cin >> n;
// for (int i = 0; i < n; i++) cin >> ac[i];
// cout << count_mushrooms(n) << "\n";
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |