Submission #486464

# Submission time Handle Problem Language Result Execution time Memory
486464 2021-11-11T17:45:46 Z rainboy Dijamant (COI16_dijament) C
100 / 100
868 ms 8472 KB
#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

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 time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 1 ms 388 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 588 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 0 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 774 ms 4112 KB Output is correct
2 Correct 868 ms 8472 KB Output is correct
3 Correct 111 ms 4548 KB Output is correct
4 Correct 2 ms 1356 KB Output is correct
5 Correct 5 ms 2728 KB Output is correct
6 Correct 13 ms 2076 KB Output is correct
7 Correct 26 ms 2184 KB Output is correct
8 Correct 40 ms 2424 KB Output is correct
9 Correct 34 ms 2168 KB Output is correct
10 Correct 12 ms 1868 KB Output is correct
11 Correct 13 ms 2012 KB Output is correct
12 Correct 728 ms 7280 KB Output is correct