Submission #479356

# Submission time Handle Problem Language Result Execution time Memory
479356 2021-10-11T13:10:47 Z rainboy Ispit (COCI19_ispit) C
81 / 90
7 ms 2764 KB
#include <stdio.h>

#define N	500
#define A	26

int min(int a, int b) { return a < b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

char cc[N][N + 1]; int cnt[N][A], n;

int compare_p(int i, int j) {
	int k;

	for (k = 0; k < n; k++)
		if (cc[i][k] != cc[j][k])
			return cc[i][k] - cc[j][k];
	return 0;
}

int compare_q(int i, int j) {
	int k;

	for (k = n - 1; k >= 0; k--)
		if (cc[i][k] != cc[j][k])
			return cc[i][k] - cc[j][k];
	return 0;
}

int compare_cnt(int i, int j) {
	int a;

	for (a = 0; a < A; a++)
		if (cnt[i][a] != cnt[j][a])
			return cnt[i][a] - cnt[j][a];
	return 0;
}

int (*compare)(int, int);

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 = compare(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 int pp[N][N], qq[N][N], ii[N];
	int k, g, h, i, i1, i2, i3, j;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++) {
		scanf("%s", cc[i]);
		for (j = 0; j < n; j++)
			cnt[i][cc[i][j] - 'a']++;
	}
	for (i = 0; i < n; i++)
		ii[i] = i;
	compare = compare_p, sort(ii, 0, n);
	for (i = 0; i + 1 < n; i++) {
		i1 = ii[i], i2 = ii[i + 1];
		j = 0;
		while (j < n && cc[i1][j] == cc[i2][j])
			j++;
		pp[i1][i2] = pp[i2][i1] = j;
	}
	for (i = 0; i < n; i++)
		for (j = i + 2; j < n; j++) {
			i1 = ii[i], i2 = ii[j - 1], i3 = ii[j];
			pp[i1][i3] = min(pp[i1][i2], pp[i2][i3]);
		}
	compare = compare_q, sort(ii, 0, n);
	for (i = 0; i + 1 < n; i++) {
		i1 = ii[i], i2 = ii[i + 1];
		j = n - 1;
		while (j >= 0 && cc[i1][j] == cc[i2][j])
			j--;
		qq[i1][i2] = qq[i2][i1] = n - 1 - j;
	}
	for (i = 0; i < n; i++)
		for (j = i + 2; j < n; j++) {
			i1 = ii[i], i2 = ii[j - 1], i3 = ii[j];
			qq[i1][i3] = qq[i3][i1] = min(qq[i1][i2], qq[i2][i3]);
		}
	compare = compare_cnt, sort(ii, 0, n);
	for (i = 0; i < n; i = j) {
		j = i + 1;
		while (j < n && compare_cnt(ii[j], ii[i]) == 0)
			j++;
		for (g = i; g < j; g++)
			for (h = i; h < j; h++)
				if (n - pp[ii[g]][ii[h]] - qq[ii[g]][ii[h]] <= k) {
					printf("DA\n");
					return 0;
				}
	}
	printf("NE\n");
	return 0;
}

Compilation message

ispit.c: In function 'main':
ispit.c:71:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
ispit.c:73:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 2 ms 1192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 2 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2508 KB Output is correct
2 Correct 6 ms 2508 KB Output is correct
3 Correct 6 ms 2764 KB Output is correct
4 Correct 6 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2452 KB Output is correct
2 Correct 7 ms 2528 KB Output is correct
3 Correct 7 ms 2508 KB Output is correct
4 Correct 7 ms 2508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2508 KB Output is correct
2 Correct 6 ms 2508 KB Output is correct
3 Correct 6 ms 2764 KB Output is correct
4 Correct 5 ms 2736 KB Output is correct