Submission #863300

#TimeUsernameProblemLanguageResultExecution timeMemory
863300HuyQuang_re_ZeroLinear Garden (IOI08_linear_garden)C++14
100 / 100
156 ms14116 KiB
#include <bits/stdc++.h> #define ll long long #define db long double #define N 1000005 #define II pair <ll,ll> #define III pair <ll,II> #define IV pair <vector <int>,vector <int> > #define fst first #define snd second #define BIT(x,i) ((x>>i)&1) #define pi acos(-1) #define to_radian(x) (x*pi/180.0) #define to_degree(x) (x*180.0/pi) #define rand(l,r) (l+rng()%(r-l+1)) #define f(cnt,mi,ma) f[cnt+2][mi+2][ma] #define g(cnt,mi,ma) g[cnt+2][mi+2][ma] using namespace std; string s; int Mi[N],Ma[N],Cnt[N],f[5][3][3],g[5][3][3],cnt,mi,ma,mod,n,i,res; void update(int &a,int b) { a+=b; if(a>=mod) a-=mod; } int main() { // freopen("linear_garden.inp","r",stdin); //freopen("linear_garden.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>mod>>s; s=" "+s; for(i=1;i<=n;i++) { Cnt[i]=Cnt[i-1]+(s[i]=='L')-(s[i]=='P'); Mi[i]=min(Mi[i-1],Cnt[i]); Ma[i]=max(Ma[i-1],Cnt[i]); } for(cnt=-2;cnt<=2;cnt++) for(mi=-2;mi<=0;mi++) for(ma=0;ma<=2;ma++) if(ma-mi<=2) f(cnt,mi,ma)=1; for(i=n;i>=1;i--) { if(s[i]=='P' && Cnt[i-1]+1<=2) update(res,f(Cnt[i-1]+1,Mi[i-1],max(Ma[i-1],Cnt[i-1]+1))); for(cnt=-2;cnt<=2;cnt++) for(mi=-2;mi<=0;mi++) for(ma=0;ma<=2;ma++) g(cnt,mi,ma)=f(cnt,mi,ma),f(cnt,mi,ma)=0; for(cnt=-2;cnt<=2;cnt++) for(mi=-2;mi<=0;mi++) for(ma=0;ma<=2;ma++) { if(cnt+1<=2) update(f(cnt,mi,ma),g(cnt+1,mi,max(ma,cnt+1))); if(cnt-1>=-2) update(f(cnt,mi,ma),g(cnt-1,min(mi,cnt-1),ma)); } } update(res,1); cout<<res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...