# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53969 | khsoo01 | Linear Garden (IOI08_linear_garden) | C++11 | 32 ms | 5516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (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... |