Submission #230005

#TimeUsernameProblemLanguageResultExecution timeMemory
230005CaroLindaLinear Garden (IOI08_linear_garden)C++14
80 / 100
74 ms65540 KiB
#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)

linear_garden.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
linear_garden.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
linear_garden.cpp: In function 'int main()':
linear_garden.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %s", &N , &M , str ) ;
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...