Submission #74729

#TimeUsernameProblemLanguageResultExecution timeMemory
74729goodbatonLinear Garden (IOI08_linear_garden)C++14
100 / 100
380 ms6776 KiB
#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)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%s",&n,&m,s);
   ~~~~~^~~~~~~~~~~~~~~~~~
#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...