# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580029 | Vanilla | Counting Mushrooms (IOI20_mushrooms) | C++17 | 11 ms | 336 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 <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
int block = 140;
int cd2 (int x) {
return x / 2 + (x % 2);
}
int count_mushrooms(int n) {
if (n <= 20) {
int rs = 0;
for (int i = 1; i < n; i++){
rs+=use_machine({0, i});
}
return n - rs;
}
block = min(n / 2, block);
if (block * 2 == n) block--;
vector <int> s0 = {0}, s1;
int p1 = use_machine({0, 1});
int p2 = use_machine({0, 2});
(p1 ? s1: s0).push_back(1);
(p2 ? s1: s0).push_back(2);
if (p1 == p2 && p1 == 1) {
for (int i = 3; i + 1 <= block * 2; i+=2){
int k = use_machine({i, 1, i + 1, 2});
(k & 1 ? s0: s1).push_back(i);
(k & 2 ? s0: s1).push_back(i + 1);
}
}
else {
int p = (p1 == 0 ? 1: 2);
for (int i = 3; i + 1 <= block * 2; i+=2){
int k = use_machine({i, 0, i + 1, p});
(k & 1 ? s1: s0).push_back(i);
(k & 2 ? s1: s0).push_back(i + 1);
}
}
bool rev = 0;
int rs = s0.size();
int oth = 0;
if (s1.size() > s0.size()) {
rev = 1;
swap(s0, s1);
}
vector <int> idx;
for (int i = block * 2 + 1; i < n; i++){
idx.push_back(s0[i % block]);
idx.push_back(i);
if (i % block == 0 || i == n - 1) {
oth+=cd2(use_machine(idx));
idx.clear();
}
}
if (!rev) oth = n - block * 2 - 1 - oth;
return rs + oth;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |