이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 1e6 + 5;
const int alp = 4;
int modu;
inline void add(int &x,int y){
x %= modu;y %= modu;
x = (x + y) % modu;
}
int dp[maxn][alp][alp];
void prepare_dp(int n){
dp[n + 1][0][0] = 1;
for (int p = n ; p > 0 ; p--){
for (int i = 0 ; i <= 2 ; i++)
for (int j = 0 ; j <= 2 ; j++){
if (i < 2)
add(dp[p][i + 1][max(j - 1,0)],dp[p + 1][i][j]);
if (j <= 2)
add(dp[p][max(i - 1,0)][j + 1],dp[p + 1][i][j]);
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
cin >> n >> modu;
prepare_dp(n);
string s;cin >> s;
int res = 0,p = 0,c1 = 0;
for (char c : s){
p++;
if (p > 1){
if (s[p - 2] == 'L')
c1++;
else
c1 = max(0,c1 - 1);
}
if (c == 'P'){
for (int i = 0 ; i + c1 + 1 <= 2 ; i++)
for (int j = 0 ; j <= 2 ; j++)
add(res,dp[p + 1][i][j]);
}
}
add(res,1);
cout << res;
return 0;
}
# | 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... |