#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
#define L 100
#define A 26
int *fa[A], fo[A], eo[A];
void append(int b, int a) {
int o = fo[b]++;
if (o >= 2 && (o & o - 1) == 0)
fa[b] = (int *) realloc(fa[b], o * 2 * sizeof *fa[b]);
fa[b][o] = a, eo[a]++;
}
int main() {
static char ss[N][L + 1], cc[A + 1];
static int ii[N], ll[N];
int n, g, h, i, j, a, b, c, 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++)
fa[a] = (int *) malloc(2 * sizeof *fa[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[j][g] - 'a', ss[i][g] - 'a');
break;
}
if (g == ll[j]) {
printf("NE\n");
return 0;
}
}
for (c = A - 1; c >= 0; c--) {
for (b = A - 1; b >= 0; b--)
if (eo[b] == 0)
break;
if (b == -1) {
printf("NE\n");
return 0;
}
cc[b] = c + 'a';
eo[b] = -1;
for (o = fo[b]; o--; ) {
a = fa[b][o];
eo[a]--;
}
}
printf("DA\n");
printf("%s\n", cc);
return 0;
}
Compilation message
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]--;
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |