Submission #405421

#TimeUsernameProblemLanguageResultExecution timeMemory
405421cgiosyLinear Garden (IOI08_linear_garden)C++17
59 / 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=0, Z=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; Y<<=N-i&1; Y=Y>=M ? Y-M : Y; if(S[i]=='P') { if(t==l && r-l<2) X+=2+(N-i-1&1), Z--; else if(t==l) X++; else if(t<l+2) Y++; l=min(l, --t); } else r=max(r, ++t); } cout<<(X+Y+Z%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:14:8: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   14 |   Y<<=N-i&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), Z--;
      |                            ~~~^~
#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...