Submission #536544

# Submission time Handle Problem Language Result Execution time Memory
536544 2022-03-13T13:45:44 Z rainboy JOIOJI (JOI14_joioji) C
100 / 100
37 ms 2996 KB
#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

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
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 5 ms 692 KB Output is correct
3 Correct 8 ms 948 KB Output is correct
4 Correct 17 ms 1596 KB Output is correct
5 Correct 26 ms 2356 KB Output is correct
6 Correct 36 ms 2900 KB Output is correct
7 Correct 33 ms 2900 KB Output is correct
8 Correct 37 ms 2900 KB Output is correct
9 Correct 34 ms 2984 KB Output is correct
10 Correct 33 ms 2900 KB Output is correct
11 Correct 24 ms 2644 KB Output is correct
12 Correct 31 ms 2876 KB Output is correct
13 Correct 29 ms 2908 KB Output is correct
14 Correct 20 ms 2468 KB Output is correct
15 Correct 28 ms 2996 KB Output is correct