# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
734830 | lucri | Linear Garden (IOI08_linear_garden) | C++17 | 95 ms | 25824 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 <bits/stdc++.h>
using namespace std;
long long n,m,pd[1000010][3],poza,sum,ans;
char s[1000010];
void RezolvaRange(long long b,long long e)
{
sum=0;
for(long long i=1;i<=n;++i)
{
if(s[i-1]=='L')
--sum;
else if(s[i-1]=='P')
++sum;
if(sum<b||sum>e)
sum=1000000000000000000;
pd[i][0]=pd[i][1]=pd[i][2]=0;
if(sum<=e&&sum>=b+1&&s[i]=='P')
++pd[i][sum-b-1];
pd[i][0]+=pd[i-1][1];
pd[i][1]+=pd[i-1][0]+pd[i-1][2];
if(e-b>=2)
pd[i][2]+=pd[i-1][1];
pd[i][0]%=m;
pd[i][1]%=m;
pd[i][2]%=m;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>s+1;
ans=1;
RezolvaRange(-2,0);
ans+=pd[n][0];
ans+=pd[n][1];
ans+=pd[n][2];
RezolvaRange(-1,1);
ans+=pd[n][0];
ans+=pd[n][1];
ans+=pd[n][2];
RezolvaRange(0,2);
ans+=pd[n][0];
ans+=pd[n][1];
ans+=pd[n][2];
RezolvaRange(-1,0);
ans-=pd[n][0];
ans-=pd[n][1];
RezolvaRange(0,1);
ans-=pd[n][0];
ans-=pd[n][1];
cout<<(ans%m+m)%m;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |