# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
230005 | CaroLinda | Linear Garden (IOI08_linear_garden) | C++14 | 74 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>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define mkt make_tuple
#define debug printf
#define all(x) x.begin(),x.end()
#define lp(i,a,b) for(int i = a ; i< b ; i++)
#define ss second
#define ff first
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mk make_pair
const int MAXN = 1e6+10 ;
using namespace std ;
int N , M ;
char str[MAXN] ;
ll dp[MAXN][5][5] ;
int main()
{
scanf("%d %d %s", &N , &M , str ) ;
for(int i = 0 ; i < 5 ; i++ )
for(int j = 0 ; j < 5 ; j++ ) dp[0][i][j] = 1LL ;
for(int tam = 1 ; tam <= N ; tam ++ )
for(int l = 0 ; l < 5 ; l++ )
for(int p = 0 ; p < 5 ; p++ )
{
if( l+1 <= 4 && p-1 >= 0 )
dp[tam][l][p] = dp[tam-1][ max(l+1,3) ][p-1] ;
if( l-1 >= 0 && p+1 <= 4 )
( dp[tam][l][p] += dp[tam-1][l-1][ max(p+1,3) ] ) %= M ;
}
int cnt = 0 , l = 2 , p = 2;
for(int i = 0 ; i < N ; i++ )
{
int lef = N - i - 1 ;
if( str[i] == 'P' )
if( l+1 <= 4 && p-1 >= 0 ) ( cnt += dp[lef][ max(l+1,3) ][p-1] ) %= M ;
if(str[i] == 'L') l = max(l+1, 3) , p -- ;
else p = max(p+1, 3) , l-- ;
}
printf("%d\n" , (cnt+1)%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... |