/* https://oi.edu.pl/static/attachment/20140306/oi20.pdf */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 2000000
#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 |
7 ms |
36952 KB |
Output is correct |
2 |
Correct |
7 ms |
37980 KB |
Output is correct |
3 |
Correct |
11 ms |
38748 KB |
Output is correct |
4 |
Correct |
15 ms |
41308 KB |
Output is correct |
5 |
Correct |
14 ms |
41428 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
16732 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
16728 KB |
Output is correct |
11 |
Correct |
121 ms |
54104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
56164 KB |
Output is correct |
2 |
Correct |
250 ms |
57924 KB |
Output is correct |
3 |
Execution timed out |
5020 ms |
192592 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
36968 KB |
Output is correct |
2 |
Correct |
85 ms |
51028 KB |
Output is correct |
3 |
Correct |
110 ms |
58908 KB |
Output is correct |
4 |
Correct |
18 ms |
43096 KB |
Output is correct |
5 |
Correct |
21 ms |
43096 KB |
Output is correct |
6 |
Correct |
7 ms |
38420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
39772 KB |
Output is correct |
2 |
Correct |
6 ms |
36188 KB |
Output is correct |
3 |
Correct |
63 ms |
52060 KB |
Output is correct |
4 |
Correct |
96 ms |
58200 KB |
Output is correct |
5 |
Correct |
100 ms |
58456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
48164 KB |
Output is correct |
2 |
Correct |
3242 ms |
212676 KB |
Output is correct |
3 |
Execution timed out |
5044 ms |
253064 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
46640 KB |
Output is correct |
2 |
Correct |
622 ms |
109976 KB |
Output is correct |
3 |
Correct |
1066 ms |
144424 KB |
Output is correct |
4 |
Correct |
1639 ms |
180048 KB |
Output is correct |
5 |
Correct |
1628 ms |
179872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
52728 KB |
Output is correct |
2 |
Correct |
4990 ms |
210788 KB |
Output is correct |
3 |
Correct |
4613 ms |
211616 KB |
Output is correct |
4 |
Correct |
2337 ms |
165016 KB |
Output is correct |
5 |
Correct |
80 ms |
47444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
52164 KB |
Output is correct |
2 |
Correct |
70 ms |
45652 KB |
Output is correct |
3 |
Correct |
1399 ms |
143420 KB |
Output is correct |
4 |
Correct |
76 ms |
48364 KB |
Output is correct |
5 |
Correct |
3326 ms |
187388 KB |
Output is correct |