Submission #405418

#TimeUsernameProblemLanguageResultExecution timeMemory
405418cgiosyLinear Garden (IOI08_linear_garden)C++17
23 / 100
7 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, nX=0; i<N; i++) { X<<=N-i-1&1; X=X>=M ? X-M : X; X+=nX; nX=0; 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) X++; else if(t<l+2) nX++; l=min(l, --t); } 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:17:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   17 |    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...