제출 #553750

#제출 시각아이디문제언어결과실행 시간메모리
553750AbdelmagedNourLinear Garden (IOI08_linear_garden)C++17
90 / 100
58 ms65536 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int MAX=1000005; int dp1[MAX][3],dp2[MAX][3],mod; int add(int a,int b){ return a+b-(a+b>=mod?mod:0); } int solve1(int n,int d){ if(d==-2||d==2)return 0; if(!n)return 1; int&ret=dp1[n][d+1]; if(~ret)return ret; ret=add(solve1(n-1,d-1),solve1(n-1,d+1)); return ret; } int solve2(int n,int d){ if(d==-1||d==3)return 0; if(!n)return 1; int&ret=dp2[n][d]; if(~ret)return ret; ret=add(solve2(n-1,d-1),solve2(n-1,d+1)); return ret; } int solve3(int n,int d){ if(d==-3||d==1)return 0; if(!n)return 1; int&ret=dp2[n][-d]; if(~ret)return ret; ret=add(solve3(n-1,d-1),solve3(n-1,d+1)); return ret; } int index(string&s){ int mn=0,mx=0,d=0,res=0,n=s.size(); for(int i=0;i<n;i++){ if(s[i]=='L'){ mn=min(mn,d-1); d--; }else{ int x=0; if(mx<=1&&min(mn,d-1)>=-1)res=add(res,solve1(n-i-1,d-1)),x+=solve1(n-i-1,d-1)>=1; // -1 to 1 if(mx<=2&&min(mn,d-1)>=0)res=add(res,solve2(n-i-1,d-1)),x+=solve2(n-i-1,d-1)>=1; // 0 to 2 if(mx<=0&&min(mn,d-1)>=-2)res=add(res,solve3(n-i-1,d-1)),x+=solve3(n-i-1,d-1)>=1; if(x>1)res=add(res,mod-1); mx=max(mx,d+1); d++; } } return add(res,1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp1,-1,sizeof(dp1)); memset(dp2,-1,sizeof(dp2)); int n; string s; cin>>n>>mod>>s; cout<<index(s); return 0; }
#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...