이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LL_MAX LONG_LONG_MAX
#define LL_MIN LONG_LONG_MIN
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ii> vii;
typedef set<ii> sii;
#define REP(i, a, b) for(int i = a; i < b; i++)
int32_t main() {
int N, M, mn=0, mx=0; string S; cin >> N >> M >> S;
int dp[N+1][3][3];
REP(k,0,N) REP(i,0,3) REP(j,0,3) dp[k][i][j]=0;
if(S[0]=='P') dp[0][1][0]=1;
REP(i,1,N) {
mn=min((int)0,mn+((S[i-1]=='P')?1:-1));
mx=max((int)0,mx+((S[i-1]=='P')?1:-1));
assert(mn>-3); assert(mx<3);
if(S[i]=='P' && mn!=-2) {dp[i][1-mn][max((int)0,mx-1)]++; dp[i][1-mn][max((int)0,mx-1)]%=M;}
REP(k,1,3) {
dp[i][0][k]+=(dp[i-1][0][k-1]+dp[i-1][1][k-1]);
dp[i][1][k]+=dp[i-1][2][k-1];
dp[i][0][k]%=M; dp[i][1][k]%=M;
}
REP(j,1,3) {
dp[i][j][0]+=(dp[i-1][j-1][0]+dp[i-1][j-1][1]);
dp[i][j][1]+=dp[i-1][j-1][2];
dp[i][j][0]%=M; dp[i][j][1]%=M;
}
}
int sum=1;
REP(i,0,3) REP(j,0,3) sum+=dp[N-1][i][j];
cout<<sum%M;
}
# | 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... |