답안 #948201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948201 2024-03-17T21:41:08 Z rainboy Walk (POI13_spa) C
62 / 100
5000 ms 178472 KB
/* https://oi.edu.pl/static/attachment/20140306/oi20.pdf */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define M	500000
#define N_	5000001
#define L	60
#define MD	0x7fffffff
 
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
 
int X = 123454321;
 
int k;
 
long long parse() {
	static char cc[L + 1];
	int h;
	long long x;
 
	scanf("%s", cc);
	x = 0;
	for (h = 0; h < k; h++)
		if (cc[h] == '1')
			x |= 1LL << h;
	return x;
}
 
long long *ek[M]; int eo[M];
char *ev[M];

int hash(long long k) {
	int kl = k / MD, kr = k % MD;

	return ((long long) kl * X % MD + kr) * X % MD % M;
}

int ht_add(long long k, int v) {
	int h = hash(k), o;

	for (o = eo[h]; o--; )
		if (ek[h][o] == k) {
			if (ev[h][o] == (v ^ 1)) {
				printf("TAK\n");
				exit(0);
			}
			return 0;
		}
	o = eo[h]++;
	if (o == 0) {
		ek[h] = (long long *) malloc(2 * sizeof *ek[h]);
		ev[h] = (char *) malloc(2 * sizeof *ev[h]);
	} else if (o >= 2 && (o & o - 1) == 0) {
		ek[h] = (long long *) realloc(ek[h], o * 2 * sizeof *ek[h]);
		ev[h] = (char *) realloc(ev[h], o * 2 * sizeof *ev[h]);
	}
	ek[h][o] = k, ev[h][o] = v;
	return 1;
}

int bfs(long long s, int cnt_, int v) {
	static long long qu[N_];
	int cnt, g, h;
	long long b, b_;

	cnt = 0;
	ht_add(s, v), qu[cnt++] = s;
	for (g = 0; g < cnt; g++) {
		b = qu[g];
		for (h = 0; h < k; h++) {
			b_ = b ^ 1LL << h;
			if (ht_add(b_, v)) {
				qu[cnt++] = b_;
				if (cnt == cnt_)
					return 1;
			}
		}
	}
	return 0;
}

int main() {
	int n, i;
	long long s, t;
 
	scanf("%d%d", &k, &n), s = parse(), t = parse();
	if (s == t) {
		printf("TAK\n");
		return 0;
	}
	for (i = 0; i < n; i++)
		ht_add(parse(), -1);
	ht_add(s, 0), ht_add(t, 1);
	printf(bfs(s, n * k + 1, 0) && bfs(t, n * k + 1, 1) ? "TAK\n" : "NIE\n");
	return 0;
}

Compilation message

spa.c: In function 'ht_add':
spa.c:55:30: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   55 |  } else if (o >= 2 && (o & o - 1) == 0) {
      |                            ~~^~~
spa.c: In function 'parse':
spa.c:23:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%s", cc);
      |  ^~~~~~~~~~~~~~~
spa.c: In function 'main':
spa.c:88:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |  scanf("%d%d", &k, &n), s = parse(), t = parse();
      |  ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11356 KB Output is correct
2 Correct 4 ms 11868 KB Output is correct
3 Correct 4 ms 11868 KB Output is correct
4 Correct 8 ms 12672 KB Output is correct
5 Correct 7 ms 12636 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 3 ms 8632 KB Output is correct
9 Correct 4 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 74 ms 22356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 23636 KB Output is correct
2 Correct 180 ms 26192 KB Output is correct
3 Execution timed out 5102 ms 107560 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 11612 KB Output is correct
2 Correct 46 ms 19540 KB Output is correct
3 Correct 71 ms 25424 KB Output is correct
4 Correct 9 ms 14168 KB Output is correct
5 Correct 9 ms 14168 KB Output is correct
6 Correct 2 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11868 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 33 ms 21852 KB Output is correct
4 Correct 53 ms 26964 KB Output is correct
5 Correct 54 ms 26972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 18764 KB Output is correct
2 Correct 3120 ms 138584 KB Output is correct
3 Execution timed out 5042 ms 178472 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 17404 KB Output is correct
2 Correct 454 ms 54672 KB Output is correct
3 Correct 1026 ms 75008 KB Output is correct
4 Correct 1953 ms 108548 KB Output is correct
5 Correct 1918 ms 108640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 22352 KB Output is correct
2 Execution timed out 5022 ms 129284 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 21892 KB Output is correct
2 Correct 50 ms 16616 KB Output is correct
3 Correct 1291 ms 72804 KB Output is correct
4 Correct 51 ms 19028 KB Output is correct
5 Correct 3775 ms 111820 KB Output is correct