Submission #53969

#TimeUsernameProblemLanguageResultExecution timeMemory
53969khsoo01Linear Garden (IOI08_linear_garden)C++11
100 / 100
32 ms5516 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1000005; int n, m, dt[N/2] = {1}, two[N/2] = {1}; char a[N]; int main() { scanf("%d%d%s",&n,&m,a+1); for(int i=1;2*i<=n;i++) { two[i] = two[i-1] * 2 % m; } if(n%2) dt[0]++; for(int i=1;2*i<=n;i++) { dt[i] = (dt[i-1] + two[i-1] + two[i-1 + n%2]) % m; } int typ = 0, ans = 1; for(int i=1;2*i<=n;i++) { if(i == 1) { if(a[1] == 'P' && a[2] == 'P') { ans = (ans + two[(n-2*i)/2] + 2 * dt[n/2-i]) % m; } if(a[1] == 'P' && a[2] == 'L') { ans = (ans + two[(n-2*i)/2] + dt[n/2-i]) % m; } if(a[1] == 'L' && a[2] == 'P') { ans = (ans + two[(n-2*i)/2]) % m; } if(a[1] == a[2]) typ = 1; } else if(typ == 1) { if(a[2*i] == 'P') { ans = (ans + two[(n-2*i)/2]) % m; } } else if(typ == 2) { if(a[2*i] == 'L') { ans = (ans + two[(n-2*i+1)/2]) % m; } } else if(a[2*i-1] == a[1] && a[2*i] == a[2]) { if(a[1] == 'P') { ans = (ans + two[(n-2*i+1)/2]) % m; } else { ans = (ans + two[(n-2*i)/2]) % m; } } else { if(a[2*i-1] == 'P') { if(a[2*i] == 'P') { ans = (ans + two[(n-2*i+1)/2] + dt[n/2-i]) % m; } else { ans = (ans + two[(n-2*i)/2] + dt[n/2-i]) % m; } } if(a[2*i-1] == a[2*i]) typ = 1; else typ = 2; } } if(typ%2 == 0 && n%2 && a[n] == 'P') { ans = (ans + 1) % m; } printf("%d\n",ans); }

Compilation message (stderr)

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