# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
337312 | Giselus | Linear Garden (IOI08_linear_garden) | C++14 | 47 ms | 6368 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |