Submission #476222

# Submission time Handle Problem Language Result Execution time Memory
476222 2021-09-25T12:22:35 Z rainboy Zamjena (COCI18_zamjena) C
14 / 70
3 ms 844 KB
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	50000

unsigned int X = 12345;

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

char ss[N * 2][16]; int aa[N * 2];

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) {
			int c = strcmp(ss[ii[j]], ss[i_]);

			if (c == 0)
				j++;
			else if (c < 0) {
				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 ds[N * 2], aa[N * 2];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

int join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return 1;
	if (aa[i] != -1 && aa[j] != -1 && aa[i] != aa[j])
		return 0;
	if (ds[i] > ds[j]) {
		ds[i] = j;
		if (aa[j] == -1)
			aa[j] = aa[i];
	} else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
		if (aa[i] == -1)
			aa[i] = aa[j];
	}
	return 1;
}

int main() {
	static int ii[N * 2];
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n * 2; i++)
		scanf("%s", ss[i]);
	sort(ii, 0, n * 2);
	for (i = 0; i < n * 2; i++)
		aa[i] = isdigit(ss[i][0]) ? atoi(ss[i]) : -1;
	memset(ds, -1, n * 2 * sizeof *ds);
	for (i = 0; i < n; i++)
		if (!join(i, n + i)) {
			printf("NE\n");
			return 0;
		}
	for (i = 0; i < n * 2; i++)
		ii[i] = i;
	for (i = 0; i < n * 2; i++)
		if (i > 0 && strcmp(ss[ii[i]], ss[ii[i - 1]]) == 0 && !join(ii[i], ii[i - 1])) {
			printf("NE\n");
			return 0;
		}
	printf("DA\n");
	return 0;
}

Compilation message

zamjena.c: In function 'main':
zamjena.c:69:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
zamjena.c:71:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%s", ss[i]);
      |   ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 0 ms 284 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -