# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74729 | goodbaton | Linear Garden (IOI08_linear_garden) | C++14 | 380 ms | 6776 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 <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
#define SIZE 1000010
int main(){
int dp[2][5][5][5][2] = {};
int n,m;
char s[SIZE];
scanf("%d%d%s",&n,&m,s);
dp[0][2][2][2][0] = 1;
for(int i=0;i<n;i++){
for(int j=2;j<=4;j++){
for(int k=j-2;k<=3;k++){
for(int l=k;l<=j;l++){
dp[1-i%2][j][k][l][0] = 0;
dp[1-i%2][j][k][l][1] = 0;
}
}
}
for(int j=2;j<=4;j++){
for(int k=j-2;k<=3;k++){
for(int l=k;l<=j;l++){
int now_dp0 = dp[i%2][j][k][l][0]%m;
int now_dp1 = dp[i%2][j][k][l][1]%m;
if(s[i]=='L'){
if(l>0 && j-(l-1) <= 2)
dp[1-i%2][j][min(k,l-1)][l-1][0] += now_dp0;
}else{
if(l>0 && j-(l-1) <= 2)
dp[1-i%2][j][min(k,l-1)][l-1][1] += now_dp0;
if(l<4 && l+1-k <= 2)
dp[1-i%2][max(j,l+1)][k][l+1][0] += now_dp0;
}
if(l>0 && j-(l-1) <= 2)
dp[1-i%2][j][min(k,l-1)][l-1][1] += now_dp1;
if(l<4 && l+1-k <= 2)
dp[1-i%2][max(j,l+1)][k][l+1][1] += now_dp1;
}
}
}
}
int ans = 0;
for(int j=2;j<=4;j++){
for(int k=j-2;k<=3;k++){
for(int l=k;l<=j;l++){
ans += dp[n%2][j][k][l][0];
ans += dp[n%2][j][k][l][1];
}
}
}
printf("%d\n",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... |