Submission #479355

# Submission time Handle Problem Language Result Execution time Memory
479355 2021-10-11T13:09:25 Z rainboy Ispit (COCI19_ispit) C
0 / 90
6 ms 2780 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 aa[N][N + 1]; int cc[N][A], n;

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

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

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

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

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

	for (a = 0; a < A; a++)
		if (cc[i][a] != cc[j][a])
			return cc[i][a] - cc[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", aa[i]);
		for (j = 0; j < n; j++)
			cc[i][aa[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 && aa[i1][j] == aa[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 && aa[i1][j] == aa[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_c, sort(ii, 0, n);
	for (i = 0; i < n; i = j) {
		j = i + 1;
		while (j < n && compare_c(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", aa[i]);
      |   ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1228 KB Output is correct
2 Correct 2 ms 1228 KB Output is correct
3 Incorrect 2 ms 1228 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1228 KB Output is correct
2 Correct 2 ms 1192 KB Output is correct
3 Incorrect 2 ms 1228 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Incorrect 2 ms 1356 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2764 KB Output is correct
2 Incorrect 5 ms 2764 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2780 KB Output is correct
2 Correct 5 ms 2708 KB Output is correct
3 Correct 6 ms 2764 KB Output is correct
4 Incorrect 6 ms 2764 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2764 KB Output is correct
2 Incorrect 5 ms 2760 KB Output isn't correct
3 Halted 0 ms 0 KB -