Submission #553760

#TimeUsernameProblemLanguageResultExecution timeMemory
553760AbdelmagedNourLinear Garden (IOI08_linear_garden)C++17
32 / 100
11 ms5352 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int N=1000005; int pw[N]={1},mod,n; string s; int add(int a,int b){ return a+b-(a+b>=mod?mod:0); } int index(){ int mn=0,mx=0,d=0,res=0; for(int i=0;i<n;i++){ if(s[i]=='L'){ mn=min(mn,d-1); d--; }else{ int x=0,mn2=min(mn,d-1),_d=d-1,_n=n-i-1; if(mx<=1&&mn2>=-1)res=add(res,pw[(_n+(_d==0))/2]),x++; if(mx<=2&&mn2>=0)res=add(res,pw[(_n+(_d==1))/2]),x++; if(mx<=0&&mn2>=-2)res=add(res,pw[(_n+(_d==-1))/2]),x++; 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); for(int i=1;i<N;i++)pw[i]=add(pw[i-1],pw[i-1]); cin>>n>>mod>>s; cout<<index(); 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...