# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
838810 | teo_thrash | Linear Garden (IOI08_linear_garden) | C++14 | 120 ms | 49280 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn=1e6+3;
const int mod=1e9+7;
int n, m;
string a;
ll dp[maxn][6];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
cin>>a;
int sz=a.size();
if(sz%2==0){
dp[sz][1]=1;
dp[sz][2]=0;
dp[sz][3]=1;
dp[sz][4]=0;
dp[sz][5]=1;
}else{
dp[sz][1]=0;
dp[sz][2]=1;
dp[sz][3]=0;
dp[sz][4]=1;
dp[sz][5]=0;
}
for(int i=sz-1; i>=0; i--){
for(int j=1; j<=5; j++){
if(i%2==0){
dp[i][1]=dp[i+1][2]%m;
dp[i][5]=dp[i+1][4]%m;
if(i+3<=sz){
dp[i][1]-=dp[i+3][4];
dp[i][1]%=m;
dp[i][5]-=dp[i+3][2];
dp[i][5]%=m;
}
dp[i][3]=(dp[i+1][2]+dp[i+1][4])%m;
}else{
dp[i][2]=(dp[i+1][1]+dp[i+1][3])%m;
dp[i][4]=(dp[i+1][3]+dp[i+1][5])%m;
if(i+3<=sz){
dp[i][2]-=dp[i+3][5];
dp[i][2]%=m;
dp[i][4]-=dp[i+3][1];
dp[i][4]%=m;
}
}
}
}
/*
for(int i=0; i<=sz; i++){
for(int j=1; j<=5; j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
ll ans=0, bal=0;
for(int i=0; i<a.size(); i++){
if(a[i]=='P'){
bal--;
if(bal<1){
ans+=dp[i+1][bal+5];
ans%=m;
}
}else{
bal++;
}
}
int add=!(n%2);
cout<<ans%m+add;
return 0;
}
컴파일 시 표준 에러 (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... |