# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
697546 | garam1732 | Counting Mushrooms (IOI20_mushrooms) | C++14 | 3 ms | 308 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;
vector<int> a, b;
int cnt = 106;
int count_mushrooms(int n) {
a.push_back(0);
if(n < 2*cnt+5) {
for(int i = 1; i < n; i++)
use_machine({0, i}) ? b.push_back(i) : a.push_back(i);
return a.size();
}
use_machine({0, 1}) ? b.push_back(1) : a.push_back(1);
use_machine({0, 2}) ? b.push_back(2) : a.push_back(2);
if(a.size() > 1) {
int x = use_machine({a[0], 3, a[1], 4});
(x&1) ? b.push_back(4) : a.push_back(4);
(x&2) ? b.push_back(3) : a.push_back(3);
}
else {
int x = use_machine({b[0], 3, b[1], 4});
(x&1) ? a.push_back(4) : b.push_back(4);
(x&2) ? a.push_back(3) : b.push_back(3);
}
int idx = 5; bool flag = false;
if(a.size() < 3) flag = true;
if(flag) swap(a, b);
while(idx <= 2*cnt) {
int x = use_machine({a[0], idx, a[1], idx+1, a[2], idx+2});
(x&1) ? b.push_back(idx+2) : a.push_back(idx+2);
if(x/2 == 0) {
a.push_back(idx);
a.push_back(idx+1);
idx += 3;
}
else if(x/2 == 2) {
b.push_back(idx);
b.push_back(idx+1);
idx += 3;
}
else if(b.size() > 1) {
int x = use_machine({b[0], idx, b[1], a[0], idx+1, a[1], idx+3, a[2], idx+4});
(x&1) ? b.push_back(idx+4) : a.push_back(idx+4);
(x&2) ? b.push_back(idx+3) : a.push_back(idx+3);
(x&4) ? b.push_back(idx+1) : a.push_back(idx+1);
(x&4) ? a.push_back(idx) : b.push_back(idx);
idx += 5;
}
else {
int x = use_machine({a[0], idx, a[1], idx+3});
(x&1) ? b.push_back(idx+3) : a.push_back(idx+3);
(x&2) ? b.push_back(idx) : a.push_back(idx);
(x&2) ? a.push_back(idx+1) : b.push_back(idx+1);
idx += 4;
}
}
if(flag) swap(a, b);
if(a.size() + b.size() == n) return a.size();
std::vector<int> m;
int res = a.size();
while(idx < n) {
if(a.size() > b.size()) {
int z;
m.clear();
for(int i = 0; i < a.size(); i++) {
if(idx < n) {
if(i == 0) z = idx;
m.push_back(idx++);
}
m.push_back(a[i]);
}
int x = use_machine(m);
res += (int)m.size() - (int)a.size() - (x+1)/2;
(x&1) ? b.push_back(z) : a.push_back(z);
}
else {
int z;
m.clear();
for(int i = 0; i < b.size(); i++) {
if(idx < n) {
if(i == 0) z = idx;
m.push_back(idx++);
}
m.push_back(b[i]);
}
int x = use_machine(m);
res += (x+1)/2;
(x&1) ? a.push_back(z) : b.push_back(z);
}
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |