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>
using namespace std;
typedef long long ll;
int main()
{
int n, m, i, s = 1, df = 0, odf;
cin >> n >> m;
char ch;
bool a, b, c, x, y, z;
a = b = c = true;
vector<int> po(n / 2 + 1);
po[0] = 1;
for (i = 1; i <= n / 2; i++)
po[i] = 2 * po[i - 1] % m;
while (n--)
{
cin >> ch;
odf = df;
if (ch == 'P')
{
odf--;
df++;
x = a;
y = b;
z = c;
if (odf < -2 || odf > 2)
continue;
if (odf < 0)
z = false;
if (odf > 0)
x = false;
if (odf == 2 || odf == -2)
y = false;
if (x || z)
{
if (df % 2 == 0)
s += po[n / 2];
else
s += po[(n + 1) / 2];
if (y)
s--;
}
if (y)
{
if (df % 2 == 0)
s += po[(n + 1) / 2];
else
s += po[n / 2];
}
s %= m;
}
else
df--;
if (df < 0)
c = false;
if (df > 0)
a = false;
if (df == 2 || df == -2)
b = false;
}
cout << s;
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... |