Submission #198898

#TimeUsernameProblemLanguageResultExecution timeMemory
198898arnold518Linear Garden (IOI08_linear_garden)C++14
59 / 100
23 ms10104 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e6; int N, M, dp[MAXN+10][2], ans=1; char S[MAXN+10]; int main() { int i, j; scanf("%d%d%s", &N, &M, S+1); dp[0][0]=dp[0][1]=1; for(i=1; i<=N; i++) { dp[i][0]=dp[i-1][1]; dp[i][1]=(dp[i-1][0]*2)%M; } int a=0, b=0, c=0; for(i=1; i<=N; i++) { if(S[i]=='P') { int cc=c+1; int aa=min(a, cc), bb=max(b, cc); if(bb-aa<=2) { int d=0; if(cc-1<=aa && bb<=cc+1) d++, ans+=dp[N-i][0]; if(cc-2<=aa && bb<=cc) d++, ans+=dp[N-i][1]; ans%=M; if(d==2) ans--, ans=(ans+M)%M; } } if(S[i]=='L') c++; else c--; a=min(a, c); b=max(b, c); } printf("%d", ans); }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:15:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
linear_garden.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%s", &N, &M, S+1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...