답안 #770027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770027 2023-06-30T17:00:08 Z rainboy "The Lyuboyn" code (IZhO19_lyuboyn) C
100 / 100
304 ms 5304 KB
#include <stdio.h>

#define N	18

int count(int b) {
	return b == 0 ? 0 : count(b & b - 1) + 1;
}

int bb_[N], n;

int add(int b) {
	int i;

	for (i = 0; i < n; i++)
		if (b & 1 << i) {
			if (bb_[i] & 1 << i)
				b ^= bb_[i];
			else {
				bb_[i] = b;
				return 1;
			}
		}
	return 0;
}

int main() {
	static char cc[N + 1];
	static int bb[N];
	int m, k, i, b, b_, x, x_;

	scanf("%d%d%*d%s", &n, &k, cc);
	x = 0;
	for (i = 0; i < n; i++)
		if (cc[i] == '1')
			x |= 1 << i;
	m = 0;
	for (b = 0; b < 1 << n; b++)
		if (count(b) == k && add(b))
			bb[m++] = b;
	if (m < n) {
		printf("-1\n");
		return 0;
	}
	printf("%d\n", 1 << n);
	for (b = 0; b < 1 << n; b++) {
		b_ = b ^ b >> 1;
		x_ = x;
		for (i = 0; i < n; i++)
			if ((b_ & 1 << i) != 0)
				x_ ^= bb[i];
		for (i = 0; i < n; i++)
			printf("%d", x_ >> i & 1);
		printf("\n");
	}
	return 0;
}

Compilation message

lyuboyn.c: In function 'count':
lyuboyn.c:6:34: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
    6 |  return b == 0 ? 0 : count(b & b - 1) + 1;
      |                                ~~^~~
lyuboyn.c: In function 'main':
lyuboyn.c:31:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d%d%*d%s", &n, &k, cc);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Ok
2 Correct 2 ms 280 KB Ok
3 Correct 2 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 1 ms 212 KB Ok
7 Correct 1 ms 212 KB Ok
8 Correct 1 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 5164 KB Ok
2 Correct 137 ms 2544 KB Ok
3 Correct 1 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 1 ms 280 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Ok
2 Correct 7 ms 340 KB Ok
3 Correct 142 ms 2604 KB Ok
4 Correct 65 ms 1272 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 2 ms 212 KB Ok
7 Correct 30 ms 672 KB Ok
8 Correct 1 ms 212 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 5232 KB Ok
2 Correct 296 ms 5228 KB Ok
3 Correct 295 ms 5304 KB Ok
4 Correct 137 ms 2636 KB Ok
5 Correct 134 ms 2608 KB Ok
6 Correct 72 ms 1280 KB Ok
7 Correct 66 ms 1332 KB Ok
8 Correct 32 ms 716 KB Ok
9 Correct 31 ms 684 KB Ok
10 Correct 16 ms 496 KB Ok
11 Correct 1 ms 212 KB Ok
12 Correct 1 ms 212 KB Ok
13 Correct 1 ms 284 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 302 ms 5164 KB Ok
2 Correct 137 ms 2544 KB Ok
3 Correct 1 ms 212 KB Ok
4 Correct 0 ms 212 KB Ok
5 Correct 1 ms 280 KB Ok
6 Correct 0 ms 212 KB Ok
7 Correct 7 ms 340 KB Ok
8 Correct 142 ms 2604 KB Ok
9 Correct 65 ms 1272 KB Ok
10 Correct 1 ms 212 KB Ok
11 Correct 2 ms 212 KB Ok
12 Correct 30 ms 672 KB Ok
13 Correct 1 ms 212 KB Ok
14 Correct 295 ms 5232 KB Ok
15 Correct 296 ms 5228 KB Ok
16 Correct 295 ms 5304 KB Ok
17 Correct 137 ms 2636 KB Ok
18 Correct 134 ms 2608 KB Ok
19 Correct 72 ms 1280 KB Ok
20 Correct 66 ms 1332 KB Ok
21 Correct 32 ms 716 KB Ok
22 Correct 31 ms 684 KB Ok
23 Correct 16 ms 496 KB Ok
24 Correct 1 ms 212 KB Ok
25 Correct 1 ms 212 KB Ok
26 Correct 1 ms 284 KB Ok
27 Correct 299 ms 5232 KB Ok
28 Correct 140 ms 2560 KB Ok
29 Correct 302 ms 5216 KB Ok
30 Correct 15 ms 468 KB Ok
31 Correct 1 ms 212 KB Ok
32 Correct 7 ms 284 KB Ok
33 Correct 31 ms 688 KB Ok
34 Correct 1 ms 212 KB Ok
35 Correct 0 ms 212 KB Ok
36 Correct 1 ms 280 KB Ok
37 Correct 0 ms 212 KB Ok
38 Correct 146 ms 2720 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 2540 KB Ok
2 Correct 304 ms 5188 KB Ok
3 Correct 296 ms 5268 KB Ok
4 Correct 15 ms 468 KB Ok
5 Correct 1 ms 212 KB Ok
6 Correct 39 ms 752 KB Ok
7 Correct 294 ms 5188 KB Ok
8 Correct 1 ms 280 KB Ok
9 Correct 1 ms 280 KB Ok
10 Correct 1 ms 212 KB Ok
11 Correct 66 ms 1360 KB Ok
12 Correct 140 ms 2572 KB Ok