Submission #486464

#TimeUsernameProblemLanguageResultExecution timeMemory
486464rainboyDijamant (COI16_dijament)C11
100 / 100
868 ms8472 KiB
#include <stdio.h>
#include <string.h>

#define N	1000
#define K	1000

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

char ss[N][16]; int n;

int idx(char *s) {
	int i;

	for (i = 0; i < n; i++)
		if (strcmp(ss[i], s) == 0)
			return i;
	return -1;
}

void add(char *s) {
	strcpy(ss[n++], s);
}

int iii[N][N], kk[N];

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)
			if (kk[ii[j]] == kk[i_])
				j++;
			else if (kk[ii[j]] > kk[i_]) {
				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() {
	int q;

	scanf("%d", &q);
	while (q--) {
		static char cc[16], aa[16], visited[N];
		static int ii[K];
		int k, ok1, ok2, ok3, h, h_, i;

		scanf("%s%*s", cc);
		k = 0, ok1 = idx(cc) == -1, ok2 = 1;
		while (1) {
			scanf("%s", aa);
			if (aa[0] == ';')
				break;
			if ((i = idx(aa)) == -1)
				ok2 = 0;
			else
				ii[k++] = i;
		}
		if (!ok1 || !ok2) {
			printf("greska\n");
			continue;
		}
		sort(ii, 0, k);
		memset(visited, 0, n * sizeof *visited);
		ok3 = 1;
		for (h = 0; h < k; h++) {
			i = ii[h];
			if (visited[i])
				continue;
			for (h_ = 0; h_ < kk[i]; h_++)
				if (!visited[iii[i][h_]])
					visited[iii[i][h_]] = 1;
				else {
					ok3 = 0;
					break;
				}
			if (!ok3)
				break;
		}
		if (ok3) {
			printf("ok\n");
			add(cc);
			visited[n - 1] = 1;
			for (i = 0; i < n; i++)
				if (visited[i])
					iii[n - 1][kk[n - 1]++] = i;
		} else
			printf("greska\n");
	}
	return 0;
}

Compilation message (stderr)

dijament.c: In function 'main':
dijament.c:52:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
dijament.c:58:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%s%*s", cc);
      |   ^~~~~~~~~~~~~~~~~~
dijament.c:61:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |    scanf("%s", aa);
      |    ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...