이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n,m,r=0; cin >> n >> m; string s; cin >> s;
vector dp(5,vector(5,vector<int>(5))); auto res = dp; for (int i(0);i < 5;++i) dp[i][i][i] = 1;
int t = 2; for (char a:s) t += (a=='L'?1:-1);
for (int i(n-1);i > -1;--i){
t -= (s[i]=='L'?1:-1);
if (s[i]=='P'&&t+1<5) for (int k(0);k < 5;++k) for (int j(0);j < 5;++j) (r += dp[t+1][k][j])%=m;
for (int u(0);u < 5;++u){
for (int k(0);k < 5;++k) for (int j(0);j < 5;++j) res[u][k][j] = 0;
if (u!=4) for (int k(0);k < 5;++k) for (int j(k);j < 4;++j) (res[u][min(k+1,u+1)][max(j+1,u+1)] += dp[u][k][j])%=m;
if (u!=0) for (int k(1);k < 5;++k) for (int j(k);j < 5;++j) (res[u][min(k-1,u-1)][max(j-1,u-1)] += dp[u][k][j])%=m;
}
swap(dp,res);
}
cout << r << endl;
}
# | 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... |