This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
res %= m;
}
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... |