Submission #824660

#TimeUsernameProblemLanguageResultExecution timeMemory
824660kwongwengCounting Mushrooms (IOI20_mushrooms)C++17
80.71 / 100
8 ms476 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define fi first #define se second #define f use_machine int count_mushrooms(int n) { int ans=0; vi A, B; A.pb(0); int a=1; int b=0; int cur=1; while (cur < n){ if (a>b){ vi val; int len=0; FOR(i,0,min(a,n-cur)){ val.pb(A[i]); val.pb(cur+i); len+=2; } int num = f(val); ans += len/2-1-num/2; if (num%2==0) {a++; A.pb(val[len-1]);} else {b++; B.pb(val[len-1]);} cur=val[len-1]+1; }else{ vi val; int len=0; FOR(i,0,min(b,n-cur)){ val.pb(B[i]); val.pb(cur+i); len+=2; } int num = f(val); ans += num/2; if (num%2==0) {b++; B.pb(val[len-1]);} else {a++; A.pb(val[len-1]);} cur=val[len-1]+1; } } return ans+a; }
#Verdict Execution timeMemoryGrader output
Fetching results...