Submission #310118

#TimeUsernameProblemLanguageResultExecution timeMemory
310118peti1234Counting Mushrooms (IOI20_mushrooms)C++17
100 / 100
9 ms512 KiB
#include <bits/stdc++.h> #include "mushrooms.h" using namespace std; vector<int> a, b, sz, s; int sa, sb, pos, ert, x, adb; bool v[20002]; void pb(int x) { sz.push_back(x); } void ap(int x) { a.push_back(x); } void bp(int x) { b.push_back(x); } void cl() { sz.clear(); } void add(int a) { if (x%2) bp(a); else ap(a); } void fadd(int a) { if (x%2) ap(a); else bp(a); } int kerd() { return use_machine(sz); } void ek(int a) { pb(0), pb(a); x=kerd(); add(a), cl(); } int count_mushrooms(int n) { ap(0), ert=sqrt(n); ert=110; if (n<220) { for (int i=1; i<n; i++) ek(i); return a.size(); } for (int i=1; i<=2; i++) ek(i); sa=a.size(); if (sa>1) { pb(a[0]), pb(3), pb(a[1]), pb(4); x=kerd(); add(4), x/=2; add(3); } else { pb(b[0]), pb(3), pb(b[1]), pb(4); x=kerd(); fadd(4), x/=2; fadd(3); } pos=5; sa=a.size(), sb=b.size(); while(max(sa, sb)<ert) { cl(); if (sa>2) { pb(a[0]), pb(pos), pb(a[1]), pb(pos+1), pb(a[2]), pb(pos+2); x=kerd(); add(pos+2); if (x<2) ap(pos), ap(pos+1), pos+=3; else if (x>=4) bp(pos), bp(pos+1), pos+=3; else { if (sb>1) { cl(); pb(b[0]), pb(pos), pb(b[1]), pb(a[0]), pb(pos+1), pb(a[1]), pb(pos+3), pb(a[2]), pb(pos+4); x=kerd()-1; add(pos+4); x/=2; add(pos+3); x/=2; add(pos+1), fadd(pos); pos+=5; } else { cl(); pb(a[0]), pb(pos), pb(a[1]), pb(pos+3); x=kerd(); add(pos+3), x/=2; add(pos), fadd(pos+1); pos+=4; } } } else { pb(b[0]), pb(pos), pb(b[1]), pb(pos+1), pb(b[2]), pb(pos+2); x=kerd(); fadd(pos+2); if (x<2) bp(pos), bp(pos+1), pos+=3; else if (x>=4) ap(pos), ap(pos+1), pos+=3; else { if (sa>1) { cl(); pb(a[0]), pb(pos), pb(a[1]), pb(b[0]), pb(pos+1), pb(b[1]), pb(pos+3), pb(b[2]), pb(pos+4); x=kerd()-1; fadd(pos+4); x/=2; fadd(pos+3); x/=2; fadd(pos+1), add(pos); pos+=5; } else { cl(); pb(b[0]), pb(pos), pb(b[1]), pb(pos+3); x=kerd(); fadd(pos+3), x/=2; fadd(pos), add(pos+1); pos+=4; } } } sa=a.size(), sb=b.size(); } while(pos<n) { cl(); if (sa>=sb) { for (int i=0; i<sa && pos+i<n; i++) { pb(a[i]), pb(pos+i); } x=kerd(); int y=sz.back(); add(y); pos=1+y; int si=sz.size(); adb+=((si-2)/2-x/2); } else { for (int i=0; i<sb && pos+i<n; i++) { pb(b[i]), pb(pos+i); } x=kerd(); int y=sz.back(); fadd(y); pos=1+y; adb+=(x/2); } sa=a.size(), sb=b.size(); } return sa+adb; }
#Verdict Execution timeMemoryGrader output
Fetching results...