Submission #926405

# Submission time Handle Problem Language Result Execution time Memory
926405 2024-02-12T22:35:48 Z rainboy Cezar (COCI16_cezar) C
30 / 100
0 ms 348 KB
#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 (a = 0; a < A; a++)
		ans[qu[a]] = a + 'a';
	printf("%s\n", ans);
	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]--;
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -