# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963437 | fzyzzz_z | Linear Garden (IOI08_linear_garden) | C++17 | 21 ms | 9172 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>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> p(1000001);
p[0] = 1;
for (int i = 1; i <= 1000000; ++i) p[i] = (p[i - 1] * 2) % m;
vector<int> a(n, 0);
for (int i = 0; i < n; ++i) {
char x; cin >> x;
if (x == 'P') a[i] = 1;
}
int ans = 0;
int v = 0;
for (int i = 0; i < n; ++i) {
if (a[i] > v) {
int c = n - 1 - i;
ans += p[c / 2];
if (i == 0 || (i > 0 && a[i] == a[i - 1])) {
ans += p[(c + 1) / 2];
ans -= 1;
}
ans %= m;
} else if (i > 0 && (a[i] + a[i - 1] == 2) || (v == 2 && a[i - 1] < a[i])) {
int c = n - 1 - i;
ans += p[c / 2];
ans %= m;
}
if (i > 0 && a[i] == a[i - 1]) v = 1 + a[i];
// cout << ans << "\n";
}
cout << (ans + 1) % m << '\n';
return 0;
}
// BABBA
// case for starting B or BB, not just ABAB since it will make ABAA
// { no AA/BB past yet
// case 1:
// B -> AA(BB)(BA).. or AB(AA)(BB)(AB)(AA)(BA) ...
// case 2:
// B -> A(BA)(BB)(AB)(AA).. or A(BB)(AB)...
// 1 overlap = ABABABABA...
// AB (at b)
// ABB -> ABA(BB) or AB(AA)B ..
// again 1 overlap
// }
// AA/BB seen already
// { can only change the BB -> BA or AB -> AA
// only 2^(v/2) ways
// }
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... |