Submission #405423

#TimeUsernameProblemLanguageResultExecution timeMemory
405423cgiosyLinear Garden (IOI08_linear_garden)C++17
100 / 100
8 ms1228 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int N, M; cin>>N>>M; char S[N+1]; cin>>S; int X=0, Y=1; for(int i=0, t=0, l=0, r=0; i<N; i++) { X<<=N-i-1&1; X=X>=M ? X-M : X; if(S[i]=='P') { if(t==l && r-l<2) X+=2+(N-i-1&1), Y--; else if(t<l+2) X++; l=min(l, --t); } else r=max(r, ++t); } cout<<(X+Y%M+M)%M<<'\n'; }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:12:10: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |   X<<=N-i-1&1;
      |       ~~~^~
linear_garden.cpp:15:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |    if(t==l && r-l<2) X+=2+(N-i-1&1), Y--;
      |                            ~~~^~
#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...