Submission #419016

#TimeUsernameProblemLanguageResultExecution timeMemory
419016pliamLinear Garden (IOI08_linear_garden)C++14
100 / 100
150 ms55972 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 1000005 int dp[MAXN][2][7];//dp[i][letter][score+3], 0=L, 1=P int N,M; int main(){ scanf("%d%d",&N,&M); for(int score=1;score<=5;score++){ dp[N][0][score]=dp[N][1][score]=1; } for(int i=N-1;i>=0;i--){ for(int score=1;score<=5;score++){ dp[i][0][score]=(dp[i+1][0][min(1,score-1)]+dp[i+1][1][score+1])%M; dp[i][1][score]=(dp[i+1][1][max(5,score+1)]+dp[i+1][0][score-1])%M; } } int ans=1,score=3,prev=-1; for(int i=0;i<N;i++){ char c; scanf(" %c",&c); if(c=='P'){ ans+=dp[i+1][0][(prev==0)?min(1,score-1):score-1]; ans%=M; score=(prev==1)?max(5,score+1):score+1; prev=1; }else{ score=(prev==0)?min(1,score-1):score-1; prev=0; } } printf("%d\n",ans); }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d%d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~
linear_garden.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf(" %c",&c);
      |         ~~~~~^~~~~~~~~~
#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...