# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39681 | 14kg | JOIOJI (JOI14_joioji) | C++11 | 33 ms | 24340 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 <stdio.h>
#include <map>
#define P 66667
#define N 200005
#define INF 999999999
#define Abs(x) (x>0?x:-(x))
#define max2(x,y) (x>y?x:y)
using namespace std;
int n;
char in[N];
map<int, int> M[N * 2];
int Find(int x, int y, int w) {
if (x == 0 && y == 0) return 0;
int res = M[x + n][y];
if (!res) M[x + n][y] = w;
return res ? res : INF;
}
int main() {
int x = 0, y = 0, w, out = 0;
scanf("%d %s", &n, in + 1);
for (int i = 1; i <= n; i++) {
if (in[i] == 'J') x++, y++;
else if (in[i] == 'O') x--;
else y--;
w = Find(x, y, i), out = max2(out, i - w);
} printf("%d", out);
}
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... |