이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
const int N = 1e6+5;
int n, mod;
ll dp[2][2][3][3];
string s;
ll sol(int i, int bit, int l, int p)
{
return dp[i%2][bit][l][p];
}
ll solve()
{
//~ if(i == n) return 1;
//~ ll &ret = dp[i][bit][l][p];
//~ if(ret != -1) return ret;
//~ ret = 0;
//~ if(bit)
//~ {
//~ if(l < 2) ret += sol(i+1, bit, l+1, max(0, p-1));
//~ if(p < 2) ret += sol(i+1, bit, max(l-1, 0), p+1), ret %= mod;
//~ }
//~ else
//~ {
//~ if(s[i] == 'L') ret += sol(i+1, bit, l+1, max(p-1, 0));
//~ else
//~ {
//~ if(l < 2) ret += sol(i+1, 1, l+1, max(p-1, 0));
//~ ret += sol(i+1, 0, max(0, l-1), p+1), ret %= mod;
//~ }
//~ }
//~ return ret;
for(int i=0; i<2; i++) for(int j=0; j<3; j++) for(int k=0; k<3; k++) dp[n%2][i][j][k] = 1;
for(int i=n-1; i>=0; i--)
{
for(int bit=0; bit<2; bit++)
{
for(int l=0; l<3; l++)
{
for(int p=0; p<3; p++)
{
ll &ret = dp[i%2][bit][l][p];
ret = 0;
if(bit)
{
if(l < 2) ret += sol(i+1, bit, l+1, max(0, p-1));
if(p < 2) ret += sol(i+1, bit, max(l-1, 0), p+1), ret %= mod;
}
else
{
if(s[i] == 'L') ret += sol(i+1, bit, l+1, max(p-1, 0));
else
{
if(l < 2) ret += sol(i+1, 1, l+1, max(p-1, 0));
ret += sol(i+1, 0, max(0, l-1), p+1), ret %= mod;
}
}
}
}
}
}
return dp[0][0][0][0];
}
int main()
{
memset(dp, -1, sizeof dp);
cin >> n >> mod >> s;
cout << solve() << 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... |