Submission #479358

#TimeUsernameProblemLanguageResultExecution timeMemory
479358rainboyIspit (COCI19_ispit)C11
81 / 90
7 ms2524 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 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 = g + 1; 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", cc[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...