# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53969 | khsoo01 | Linear Garden (IOI08_linear_garden) | C++11 | 32 ms | 5516 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<bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, m, dt[N/2] = {1}, two[N/2] = {1};
char a[N];
int main()
{
scanf("%d%d%s",&n,&m,a+1);
for(int i=1;2*i<=n;i++) {
two[i] = two[i-1] * 2 % m;
}
if(n%2) dt[0]++;
for(int i=1;2*i<=n;i++) {
dt[i] = (dt[i-1] + two[i-1] + two[i-1 + n%2]) % m;
}
int typ = 0, ans = 1;
for(int i=1;2*i<=n;i++) {
if(i == 1) {
if(a[1] == 'P' && a[2] == 'P') {
ans = (ans + two[(n-2*i)/2] + 2 * dt[n/2-i]) % m;
}
if(a[1] == 'P' && a[2] == 'L') {
ans = (ans + two[(n-2*i)/2] + dt[n/2-i]) % m;
}
if(a[1] == 'L' && a[2] == 'P') {
ans = (ans + two[(n-2*i)/2]) % m;
}
if(a[1] == a[2]) typ = 1;
}
else if(typ == 1) {
if(a[2*i] == 'P') {
ans = (ans + two[(n-2*i)/2]) % m;
}
}
else if(typ == 2) {
if(a[2*i] == 'L') {
ans = (ans + two[(n-2*i+1)/2]) % m;
}
}
else if(a[2*i-1] == a[1] && a[2*i] == a[2]) {
if(a[1] == 'P') {
ans = (ans + two[(n-2*i+1)/2]) % m;
}
else {
ans = (ans + two[(n-2*i)/2]) % m;
}
}
else {
if(a[2*i-1] == 'P') {
if(a[2*i] == 'P') {
ans = (ans + two[(n-2*i+1)/2] + dt[n/2-i]) % m;
}
else {
ans = (ans + two[(n-2*i)/2] + dt[n/2-i]) % m;
}
}
if(a[2*i-1] == a[2*i]) typ = 1;
else typ = 2;
}
}
if(typ%2 == 0 && n%2 && a[n] == 'P') {
ans = (ans + 1) % m;
}
printf("%d\n",ans);
}
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... |