Submission #536544

#TimeUsernameProblemLanguageResultExecution timeMemory
536544rainboyJOIOJI (JOI14_joioji)C11
100 / 100
37 ms2996 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...