Submission #595812

#TimeUsernameProblemLanguageResultExecution timeMemory
595812MadokaMagicaFanCounting Mushrooms (IOI20_mushrooms)C++14
0 / 100
0 ms208 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int,int>; #define all(v) v.begin(),v.end() #define sort(v) sort(all(v)) #define endl '\n' #define forn(i,n) for(int i = 0; i < n; ++i) #define forbe(i,b,e) for(int i = b; i < e; ++i) #define forr(i,n) for(int i = n-1; i >= 0; --i) #define sz(v) ((int)v.size()) #define pb push_back #define f first #define s second const int S = 82; int use_machine(vi x); int count_mushrooms(int n) { int j, i, val, ans = 0, pnt = 3; if (n < 230) { for (i = 1; i < n; ++i) ans += (1 - use_machine({0,1})); return ans; } vi a, b, ask; a.pb(0); for (i = 1; i < 3; ++i) if (use_machine({0,i})) b.pb(i); else a.pb(i); if (sz(b) > sz(a)) swap(a,b); for (i = 0; i < S; ++i) { ask.clear(); ask = {a[0], pnt++, a[1], pnt++}; val = use_machine(ask); if (val&1) b.pb(pnt-1); else a.pb(pnt-1); if (val&2) b.pb(pnt-2); else a.pb(pnt-2); } if (a[0] != 0) swap(a,b); ans = sz(a); while (pnt < n) { ask.clear(); if (sz(a) > sz(b)) { while (pnt < n && sz(ask) < (sz(a)<<1)) { ask.pb(a[sz(ask)>>1]); ask.pb(pnt++); } ans += (sz(ask)>>1); val = use_machine(ask); ans -= ((val+1)>>1); if (val&1) b.pb(ask[sz(ask)-1]); else a.pb(ask[sz(ask)-1]); } else { while (pnt < n && sz(ask) < (sz(b)<<1)) { ask.pb(b[sz(ask)>>1]); ask.pb(pnt++); } val = use_machine(ask); ans += ((val+1)>>1); if (val&1) a.pb(ask[sz(ask)-1]); else b.pb(ask[sz(ask)-1]); } } return ans; } #ifdef ONPC vi rans; int cnt = 0; int use_machine(vi x){ ++ cnt; int _ans = 0; // cout << "ASK: "; // forn(i , sz(x)) // cout << x[i] << ' '; // cout << endl; forn(i , sz(x)-1) if (rans[x[i]] != rans[x[i+1]]) ++_ans; // cout << "ANSWER: " << _ans << endl; return _ans; } void solve() { int n; cin >> n; rans.resize(n); char c; int ranswer = 0; forn(i, n) { cin >> c; rans[i]=(c=='A'); if (c=='A') ++ranswer; } int cans = count_mushrooms(n); /* if (cans != ranswer) */ /* forn(i, n) */ /* cout << rans[i] << ' '; */ cout << endl; cout << cans << ' ' << ranswer << endl; cout << n << ' ' << cnt << endl; } int main() { // freopen("in", "r", stdin); // ios_base::sync_with_stdio(0);cin.tie(0); solve(); } #endif

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:25:9: warning: unused variable 'j' [-Wunused-variable]
   25 |     int j, i, val, ans = 0, pnt = 3;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...