# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
434550 | rqi | Counting Mushrooms (IOI20_mushrooms) | C++14 | 11 ms | 652 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;
typedef vector<int> vi;
#define pb push_back
#define bk back()
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
mt19937 rng(127);
int count_mushrooms(int n) {
vi known[2];
vi untested;
int ans = 1;
known[0].pb(0);
for(int i = 1; i < n; i++){
untested.pb(i);
}
shuffle(all(untested), rng);
const int BLOCK = sqrt(n);
vi p = vi{0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0};
while(sz(untested)){
int better_ind = 0;
if(sz(known[1]) > sz(known[0])) better_ind = 1;
if(true){
vi to_test;
int special = untested.bk; untested.pop_back();
to_test.pb(special);
to_test.pb(known[better_ind][0]);
vi tested;
int to_go = sz(untested);
for(int i = 1; i < min(to_go, sz(known[better_ind])); i++){
tested.pb(untested.bk);
to_test.pb(untested.bk); untested.pop_back();
to_test.pb(known[better_ind][i]);
}
int res = use_machine(to_test);
int special_identity = better_ind;
if(res % 2 == 0){
}
else{
special_identity^=1;
}
known[special_identity].pb(special);
if(special_identity == 0){
ans++;
}
// cout << sz(known[better_ind]) << "\n";
// cout << res/2 << " " << sz(tested) << "\n";
if(res/2 == sz(tested)){
for(auto u: tested){
known[better_ind^1].pb(u);
}
}
else if(res/2 == 0){
for(auto u: tested){
known[better_ind].pb(u);
}
}
if(better_ind == 0){
ans+=sz(tested)-res/2;
}
else{
ans+=res/2;
}
}
// else{
// cout << "DOING SPECIAL" << "\n";
// vi to_test;
// vi tested;
// cout << "sz(known[better_ind]):" << " " << sz(known[better_ind]) << "\n";
// cout << "sz(untested): " << sz(untested) << "\n";
// int to_go = sz(untested);
// for(int i = 0; i < min(to_go, 2*sz(known[better_ind])); i++){
// tested.pb(untested.bk); untested.pop_back();
// }
// cout << "tested: ";
// for(auto u: tested){
// cout << u << " ";
// }
// cout << "\n";
// for(auto u: tested){
// cout << p[u] << " ";
// }
// cout << "\n";
// to_test.pb(tested[0]);
// to_test.pb(known[better_ind][0]);
// for(int i = 1; i+1 < sz(tested); i+=2){
// to_test.pb(tested[i]);
// to_test.pb(tested[i+1]);
// to_test.pb(known[better_ind][(i+1)/2]);
// }
// if(sz(tested) % 2 == 0){
// to_test.pb(tested.bk);
// }
// cout << "to_test: ";
// for(auto u: to_test){
// cout << u << " ";
// }
// cout << "\n";
// for(auto u: to_test){
// cout << p[u] << " ";
// }
// cout << "\n";
// int res = use_machine(to_test);
// cout << "res: " << res << "\n";
// // cout << sz(known[better_ind]) << "\n";
// // cout << res/2 << " " << sz(tested) << "\n";
// // if(res/2 == sz(tested)){
// // for(auto u: tested){
// // known[better_ind^1].pb(u);
// // }
// // }
// // else if(res/2 == 0){
// // for(auto u: tested){
// // known[better_ind].pb(u);
// // }
// // }
// if(better_ind == 0){
// ans+=sz(tested)-res;
// }
// else{
// ans+=res;
// }
// }
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |