이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long MOD;
string s;
cin >> n >> MOD >> s;
vector<long long> pw(n + 1);
pw[0] = 1;
for (int i = 1; i <= n; i++) {
pw[i] = (pw[i - 1] * 2) % MOD;
}
long long ans = 0;
int lo = 0, hi = 0, cur = 0;
int k = n;
for (auto& c : s) {
k--;
if (c == 'P') {
int tmp = cur + 1;
int tmp_lo = min(lo, tmp);
int tmp_hi = max(hi, tmp);
if (tmp_hi - tmp_lo == 2) {
if (tmp == (tmp_hi + tmp_lo) / 2) {
ans = (ans + pw[(k + 1) / 2]) % MOD;
} else {
ans = (ans + pw[k / 2]) % MOD;
}
} else if (tmp_hi - tmp_lo == 1) {
ans = ((ans + pw[k / 2] + pw[(k + 1) / 2] - 1) % MOD + MOD) % MOD;
}
}
if (c == 'L') {
cur++;
} else {
cur--;
}
lo = min(lo, cur);
hi = max(hi, cur);
}
cout << (ans + 1) % MOD << '\n';
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... |