Submission #405393

#TimeUsernameProblemLanguageResultExecution timeMemory
405393cgiosyLinear Garden (IOI08_linear_garden)C++17
41 / 100
7 ms2168 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') { l=min(l, --t); if(l==-1 && r==0) X+=(N-i-1&1)+2, Y--; else if(t==l) X+=1; } else r=max(r, ++t); } cout<<(X+Y)%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:16:29: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   16 |    if(l==-1 && r==0) X+=(N-i-1&1)+2, 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...