Submission #479355

#TimeUsernameProblemLanguageResultExecution timeMemory
479355rainboyIspit (COCI19_ispit)C11
0 / 90
6 ms2780 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...