Submission #481410

# Submission time Handle Problem Language Result Execution time Memory
481410 2021-10-20T17:35:05 Z rainboy Klasika (COCI20_klasika) C
33 / 110
5000 ms 3892 KB
#include <stdio.h>
#include <stdlib.h>

#define N	200000

int max(int a, int b) { return a > b ? a : b; }

int *ej[N], eo[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o == 0 || o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], (o == 0 ? 2 : o * 2) * sizeof *ej[i]);
	ej[i][o] = j;
}

int aa[N];

int dfs(int i, int a) {
	int x = aa[i] ^ a, o;

	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		x = max(x, dfs(j, a));
	}
	return x;
}

int main() {
	int n, q;

	scanf("%d", &q);
	n = 1;
	while (q--) {
		static char s[8];
		int i, j;

		scanf("%s%d", s, &i), i--;
		if (s[0] == 'A') {
			j = n++;
			scanf("%d", &aa[j]), aa[j] ^= aa[i];
			append(i, j);
		} else {
			scanf("%d", &j), j--;
			printf("%d\n", dfs(j, aa[i]));
		}
	}
	return 0;
}

Compilation message

klasika.c: In function 'append':
klasika.c:13:33: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o == 0 || o >= 2 && (o & o - 1) == 0)
      |                               ~~^~~
klasika.c:13:23: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   13 |  if (o == 0 || o >= 2 && (o & o - 1) == 0)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
klasika.c: In function 'main':
klasika.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
klasika.c:40:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%s%d", s, &i), i--;
      |   ^~~~~~~~~~~~~~~~~~~~
klasika.c:43:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |    scanf("%d", &aa[j]), aa[j] ^= aa[i];
      |    ^~~~~~~~~~~~~~~~~~~
klasika.c:46:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    scanf("%d", &j), j--;
      |    ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 3 ms 296 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 296 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5022 ms 3892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 3 ms 296 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 296 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Execution timed out 5022 ms 3892 KB Time limit exceeded
26 Halted 0 ms 0 KB -