제출 #615883

#제출 시각아이디문제언어결과실행 시간메모리
615883Koosha_mv버섯 세기 (IOI20_mushrooms)C++14
76.61 / 100
29 ms32472 KiB
#include "mushrooms.h" #include <bits/stdc++.h> using namespace std; #define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl #define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl #define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl #define eror(x) cout<<#x<<'='<<(x)<<endl #define f_(i,a,b) for(int i=a;i>=b;i--) #define f(i,a,b) for(int i=a;i<b;i++) #define nb(x) __builtin_popcount(x) #define all(v) v.begin(),v.end() #define bit(n,k) (((n)>>(k))&1) #define Add(x,y) x=(x+y)%mod #define maxm(a,b) a=max(a,b) #define minm(a,b) a=min(a,b) #define lst(x) x[x.size()-1] #define sz(x) int(x.size()) #define mp make_pair #define ll long long #define pb push_back #define S second #define F first const int N=20202,M=404; int n,ans,mark[N],dp[N][M]; vector<int> A,B; int calc(int n,int x){ if(n<=0 || x>=M) return 0; if(dp[n][x]!=-1) return dp[n][x]; return dp[n][x]=min(calc(n-2,x+2),calc(n-(x+1)/2,x+1))+1; } int get(int l,int r){ vector<int> vec; f(i,l,r+1) vec.pb(i); //dbgv(vec); return use_machine(vec); } int get(vector<int> vec){ if(vec.size()<=A.size()){ vector<int> res; f(i,0,int(vec.size())) res.pb(vec[i]),res.pb(A[i]); int prt=use_machine(res); if(prt&1) B.pb(vec[0]); else A.pb(vec[0]); prt=(prt+1)/2; return int(vec.size())-prt; } else{ vector<int> res; f(i,0,int(vec.size())) res.pb(vec[i]),res.pb(B[i]); int prt=use_machine(res); if(prt&1) A.pb(vec[0]); else B.pb(vec[0]); prt=(prt+1)/2; return prt; } } int count_mushrooms(int _n) { f(i,0,N) f(j,0,M) dp[i][j]=-1; n=_n; mark[0]=mark[1]=1; A.pb(0); int now=use_machine({0,1}); if(now==0){ A.pb(1); } else{ B.pb(1); } int l=1,r=n; while(l+1<r){ int mid=(l+r)>>1;; if(now==get(0,mid)) l=mid; else r=mid; } if(r==n && now==0){ return n; } if(r==n && now==1){ mark[2]=1; B.pb(2); } else{ if(get(0,r)&1){ B.pb(r); } else{ A.pb(r); } } mark[r]=1; //dbgv(A); //dbgv(B); ans=A.size(); vector<int> al,vec; f(i,0,n) if(!mark[i]) al.pb(i); while(al.size()){ int i=al.back(); //eror(i); al.pop_back(); vec.pb(i); int m=int(al.size())+2,sz=A.size()+B.size(); if(0 && vec.size()==2 && calc(m-2,sz+2)<calc(m-(sz+1)/2,sz+1)){ if(A.size()>=2 && B.size()>=1){ vector<int> res; res.pb(A[0]); res.pb(vec[0]); res.pb(A[1]); res.pb(B[0]); res.pb(vec[1]); int prt=use_machine(res)-1; if(prt&2){ B.pb(vec[0]); } else{ ans++; A.pb(vec[0]); } if(prt&1){ ans++; A.pb(vec[1]); } else{ B.pb(vec[1]); } } else{ vector<int> res; res.pb(B[0]); res.pb(vec[0]); res.pb(B[1]); res.pb(A[0]); res.pb(vec[1]); int prt=use_machine(res)-1; if(prt&2){ ans++; A.pb(vec[0]); } else{ B.pb(vec[0]); } if(prt&1){ B.pb(vec[1]); } else{ ans++; A.pb(vec[1]); } } vec.clear(); } else if(int(vec.size())>=max(int(A.size()),int(B.size()))){ ans+=get(vec); vec.clear(); } } if(vec.size()){ ans+=get(vec); } //eror(ans); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...