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 <stdio.h>
#define N 200000
int max(int a, int b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N + 1], yy[N + 1];
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = xx[ii[j]] != xx[i_] ? xx[ii[j]] - xx[i_] : (yy[ii[j]] != yy[i_] ? yy[ii[j]] - yy[i_] : ii[j] - i_);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int main() {
static char cc[N + 1];
static int ii[N + 1];
int n, i, j, l;
scanf("%d%s", &n, cc);
for (i = 0; i < n; i++) {
xx[i + 1] = xx[i], yy[i + 1] = yy[i];
if (cc[i] == 'J')
xx[i + 1]++, yy[i + 1]++;
else if (cc[i] == 'O')
xx[i + 1]--;
else
yy[i + 1]--;
}
for (i = 0; i <= n; i++)
ii[i] = i;
sort(ii, 0, n + 1);
l = 0;
for (i = 0; i <= n; i = j) {
j = i + 1;
while (j <= n && xx[ii[j]] == xx[ii[i]] && yy[ii[j]] == yy[ii[i]])
j++;
l = max(l, ii[j - 1] - ii[i]);
}
printf("%d\n", l);
return 0;
}
Compilation message (stderr)
joioji.c: In function 'main':
joioji.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%s", &n, cc);
| ^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |