# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
824721 | kwongweng | Counting Mushrooms (IOI20_mushrooms) | C++17 | 7 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 "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
// max # use of f : 280
// goal : 226
/*
60 - 91.8699
*/
int lim=80;
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){
if (a>=2 && a<=lim && cur<n-1){
int num = f({A[0],cur,A[1],cur+1});
if (num%2==1) {B.pb(cur+1); b++;}
else {A.pb(cur+1); a++;}
if (num>=2) {B.pb(cur); b++;}
else {A.pb(cur); a++;}
cur=cur+2; continue;
}
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{
if (b>=2 && b<=lim && cur<n-1){
int num = f({B[0],cur,B[1],cur+1});
if (num%2==0) {B.pb(cur+1); b++;}
else {A.pb(cur+1); a++;}
if (num<2) {B.pb(cur); b++;}
else {A.pb(cur); a++;}
cur=cur+2; continue;
}
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |