# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
297156 | Bill_00 | Linear Garden (IOI08_linear_garden) | C++14 | 252 ms | 65540 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>
#define pb push_back
#define pp push
#define ff first
#define ss second
#define ll long long
#define mp make_pair
using namespace std;
unordered_map<long long,unordered_map<long long,unordered_map<long long,long long> > >u;
int main(){
long long n,m;
cin >> n >> m;
string s;
cin >> s;
u[0][0][0]=1;
for(int i=1;i<=n;i++){
int o=0;
u[i][2][0]=(u[i-1][1][0]+u[i-1][1][-1])%m;
u[i][2][-1]=u[i-1][1][-2];
u[i][1][0]=(u[i-1][0][0]+u[i-1][0][-1])%m;
u[i][1][-1]=(u[i-1][2][0]+u[i-1][0][-2])%m;
u[i][1][-2]=u[i-1][2][-1];
u[i][0][-1]=(u[i-1][0][0]+u[i-1][1][0])%m;
u[i][0][-2]=(u[i-1][0][-1]+u[i-1][1][-1])%m;
}
int mx=0,mn=0;
long long ans=0;
for(int i=0;i<n-1;i++){
if(s[i]=='L'){
mx+=1;
mn=min(mn+1,0);
continue;
}
int mx_=mx+1;
int mn_=min(mn+1,0);
for(int j=0;j<=2-mx_;j++){
for(int k=0;k>=-2-mn_;k--){
ans=(ans+u[n-i-1][j][k])%m;
//cout << n-i-1 << ' ' << j << ' ' << k << ' ' << u[n-i-1][j][k] << endl;
}
}
mx=max(0,mx-1);
mn--;
}
if(s[n-1]=='P'){
if(mx!=2) ans++;
}
ans++;
cout << ans%m;
}
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... |