Submission #926404

#TimeUsernameProblemLanguageResultExecution timeMemory
926404rainboyCezar (COCI16_cezar)C11
20 / 100
1 ms856 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100 #define L 100 #define A 26 int *eb[A], eo[A], fo[A]; void append(int a, int b) { int o = eo[a]++; if (o >= 2 && (o & o - 1) == 0) eb[a] = (int *) realloc(eb[a], o * 2 * sizeof *eb[a]); eb[a][o] = b, fo[b]++; } int main() { static char ss[N][L + 1], ans[A + 1]; static int ii[N], ll[N], qu[A]; int n, cnt, g, h, i, j, a, b, o; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s", ss[i]), ll[i] = strlen(ss[i]); for (h = 0; h < n; h++) scanf("%d", &ii[h]), ii[h]--; for (a = 0; a < A; a++) eb[a] = (int *) malloc(2 * sizeof *eb[a]); for (h = 0; h + 1 < n; h++) { i = ii[h], j = ii[h + 1]; for (g = 0; g < ll[i] && g < ll[j]; g++) if (ss[i][g] != ss[j][g]) { append(ss[i][g] - 'a', ss[j][g] - 'a'); break; } if (g == ll[j]) { printf("NE\n"); return 0; } } cnt = 0; for (a = 0; a < A; a++) if (fo[a] == 0) qu[cnt++] = a; for (h = 0; h < cnt; h++) { a = qu[h]; for (o = eo[a]; o--; ) { b = eb[a][o]; if (--fo[b] == 0) qu[cnt++] = b; } } if (cnt != A) { printf("NE\n"); return 0; } printf("DA\n"); for (h = 0; h < A; h++) ans[h] = qu[h] + 'a'; printf("%s\n", ans); return 0; }

Compilation message (stderr)

cezar.c: In function 'append':
cezar.c:14:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   14 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
cezar.c: In function 'main':
cezar.c:24:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
cezar.c:26:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%s", ss[i]), ll[i] = strlen(ss[i]);
      |   ^~~~~~~~~~~~~~~~~~
cezar.c:28:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   scanf("%d", &ii[h]), ii[h]--;
      |   ^~~~~~~~~~~~~~~~~~~
#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...