# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71498 | RezwanArefin01 | Linear Garden (IOI08_linear_garden) | C++17 | 38 ms | 10572 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;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e6 + 10;
int f[N], n, M;
char s[N];
int main(int argc, char const *argv[]) {
scanf("%d %d", &n, &M);
scanf(" %s", s);
int len = strlen(s);
f[0] = 1;
for(int i = 1; i < N; i++)
f[i] = f[i - 1] * 2ll % M;
int idx = 1, bal = 0, mn = 0, mx = 0;
#define add(x, y) {x += y; if(x >= M) x -= M;}
#define sub(x, y) {x -= y; if(x < 0) x += M;}
for(int i = 0; i < len; i++) {
if(s[i] == 'L') {
mx = max(mx, ++bal);
} else {
int bal2 = bal + 1;
int mn2 = min(mn, bal2);
int mx2 = max(mx, bal2);
int rem = n - i - 1;
mn = min(mn, --bal);
if(mx2 - mn2 > 2) continue;
if(mx2 - mn2 == 2) {
if(mn2 < bal2 && bal2 < mx2){
add(idx, f[rem + 1 >> 1]);
} else add(idx, f[rem >> 1]);
} else {
add(idx, f[rem >> 1]);
add(idx, f[rem + 1 >> 1]);
sub(idx, 1);
}
}
}
printf("%d\n", idx);
}
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... |