이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#define int int64_t
using namespace std;
signed main()
{
int n, m;
string st;
cin >> n >> m >> st;
vector<vector<int>> nrstrings(n + 1, vector<int>(3, 0));
nrstrings[0][0] = 1;
nrstrings[1][0] = 1;
for (int i = 2; i <= n; i++)
{
nrstrings[i][1] += nrstrings[i - 1][0];
nrstrings[i][1] += nrstrings[i - 1][2];
if (i > 1)
{
nrstrings[i][0] += nrstrings[i - 2][0];
nrstrings[i][1] += nrstrings[i - 2][1];
nrstrings[i][2] += nrstrings[i - 2][2];
}
if (i > 2)
{
nrstrings[i][2] += nrstrings[i - 3][0];
nrstrings[i][2] += nrstrings[i - 3][1];
}
nrstrings[i][0] %= m;
nrstrings[i][1] %= m;
nrstrings[i][2] %= m;
}
int res = 1;
char bef = '0';
char doub = '1';
for (int i = 0; i < n; i++)
{
if (st[i] == 'P' && bef != doub)
{
res += nrstrings[n - i][0];
if (doub != 'P' || bef == 'L') res += nrstrings[n - i][2];
if (doub != 'L' && bef != 'L') res += nrstrings[n - i][1];
}
if (st[i] == bef)
{
doub = st[i];
}
bef = st[i];
}
cout << res << "\n";
}
# | 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... |