# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
842937 | anha3k25cvp | Linear Garden (IOI08_linear_garden) | C++14 | 282 ms | 65536 KiB |
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 <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>
using namespace std;
const int N = 5 + 1e5;
const int inf = 7 + 1e9;
int main() {
#define TASKNAME ""
ios_base :: sync_with_stdio (0);
cin.tie (0);
if ( fopen( TASKNAME".inp", "r" ) ) {
freopen (TASKNAME".inp", "r", stdin);
freopen (TASKNAME".out", "w", stdout);
}
int n, m;
string s;
cin >> n >> m >> s;
vector <int> a(n + 10, 0);
for (int i = 1; i <= n; i ++)
a[i] = s[i - 1] == 'P';
vector <vector <vector <int>>> f(n + 10, vector <vector <int>> (10, vector <int> (10, 0)));
for (int mi = 0; mi <= 4; mi ++)
for (int ma = mi; ma <= 4; ma ++) {
vector <vector <vector <int>>> g(n + 10, vector <vector <int>> (10, vector <int> (10, 0)));
g[0][mi][ma] = 1;
for (int num = 0; num < n; num ++)
for (int i = 0; i <= 4; i ++)
for (int j = i; j <= 4; j ++) {
if (i > 0) {
int i_ = min(i - 1, 1), j_ = max(j - 1, 1);
g[num + 1][i_][j_] = (g[num + 1][i_][j_] + g[num][i][j]) % m;
}
if (j < 4) {
int i_ = min(i + 1, 3), j_ = max(j + 1, 3);
g[num + 1][i_][j_] = (g[num + 1][i_][j_] + g[num][i][j]) % m;
}
}
for (int num = 0; num <= n; num ++)
for (int i = 0; i <= 4; i ++)
for (int j = i; j <= 4; j ++)
f[num][mi][ma] = (f[num][mi][ma] + g[num][i][j]) % m;
}
int mi = 2, ma = 2, ans = 1;
for (int i = 1; i <= n; i ++) {
if (a[i] && mi > 0) {
int mi_ = min(mi - 1, 1), ma_ = max(ma - 1, 1);
ans = (ans + f[n - i][mi_][ma_]) % m;
}
if (!a[i]) {
mi = min(mi - 1, 1);
ma = max(ma - 1, 1);
}
else {
mi = min(mi + 1, 3);
ma = max(ma + 1, 3);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |