Submission #337312

#TimeUsernameProblemLanguageResultExecution timeMemory
337312GiselusLinear Garden (IOI08_linear_garden)C++14
100 / 100
47 ms6368 KiB
#include<cstdio> #include<algorithm> #include<iostream> using namespace std; int pot[1000007]; int main(void){ int n,m,a,b,c,d,x; int ma = 0, mi = 0; string s; scanf("%d %d",&n,&m); cin >> s; pot[0] = 1; for(int i = 1; i<=n+3;i++){ pot[i] = pot[i-1] * 2; pot[i] %= m; } int odp = 0; int cur = 0; for(int i =1; i <= n;i++){ if(s[i-1] == 'L'){ cur++; ma = max(ma,cur); }else{ cur--; if(cur == -2){ if(mi == -2){ odp += pot[(n-i)/2]; }else{ odp += pot[(n-i)/2]; odp += pot[(n-i+1)/2]-1; } } if(cur == -1 && mi == -1){ odp += pot[(n-i)/2]; } if(cur == -1 && mi == 0){ odp += pot[(n-i)/2]; odp += pot[(n-i+1)/2]-1; } if(cur == 0 && mi == 0){ odp += pot[(n-i)/2]; } mi = min(mi,cur); //printf("%d %d\n",i,odp); odp %= m; } } odp++; odp %= m; printf("%d",odp); return 0; }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:9:9: warning: unused variable 'a' [-Wunused-variable]
    9 | int n,m,a,b,c,d,x;
      |         ^
linear_garden.cpp:9:11: warning: unused variable 'b' [-Wunused-variable]
    9 | int n,m,a,b,c,d,x;
      |           ^
linear_garden.cpp:9:13: warning: unused variable 'c' [-Wunused-variable]
    9 | int n,m,a,b,c,d,x;
      |             ^
linear_garden.cpp:9:15: warning: unused variable 'd' [-Wunused-variable]
    9 | int n,m,a,b,c,d,x;
      |               ^
linear_garden.cpp:9:17: warning: unused variable 'x' [-Wunused-variable]
    9 | int n,m,a,b,c,d,x;
      |                 ^
linear_garden.cpp:12:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 | scanf("%d %d",&n,&m);
      | ~~~~~^~~~~~~~~~~~~~~
#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...