답안 #478266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478266 2021-10-06T18:51:00 Z rainboy Sajam (COCI18_sajam) C
90 / 90
230 ms 6420 KB
#include <stdio.h>

#define N	1000
#define K	50
#define L	20

int min(int a, int b) { return a < b ? a : b; }

int cnt[1 << L];

void init() {
	int b;

	for (b = 1; b < 1 << L; b++)
		cnt[b] = cnt[b & b - 1] + 1;
}

int dist(int *aa, int *bb) {
	int h, d;

	d = 0;
	for (h = 0; h < K; h++)
		d += cnt[aa[h] ^ bb[h]];
	return d;
}

int main() {
	static char cc[N][N + 1];
	static int aa[N][K];
	int n, k_, i, i_, j;

	init();
	scanf("%d%d", &n, &k_);
	for (i = 0; i < n; i++) {
		scanf("%s", cc[i]);
		for (j = 0; j < n; j++)
			if (cc[i][j] == 'o')
				aa[i][j / L] |= 1 << j % L;
	}
	for (i = 0; i < n; i++) {
		int k;

		k = 0;
		for (i_ = 0; i_ < n; i_++) {
			int d = dist(aa[i], aa[i_]);

			k += min(d, n - d);
		}
		if (k <= k_) {
			printf("DA\n");
			return 0;
		}
	}
	for (j = 0; j < n; j++) {
		int k;

		aa[0][j / L] ^= 1 << j % L;
		k = 0;
		for (i = 0; i < n; i++) {
			int d = dist(aa[0], aa[i]);

			k += min(d, n - d);
		}
		if (k <= k_) {
			printf("DA\n");
			return 0;
		}
		aa[0][j / L] ^= 1 << j % L;
	}
	printf("NE\n");
	return 0;
}

Compilation message

sajam.c: In function 'init':
sajam.c:15:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |   cnt[b] = cnt[b & b - 1] + 1;
      |                    ~~^~~
sajam.c: In function 'main':
sajam.c:33:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d", &n, &k_);
      |  ^~~~~~~~~~~~~~~~~~~~~~
sajam.c:35:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4428 KB Output is correct
2 Correct 4 ms 4812 KB Output is correct
3 Correct 5 ms 4940 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4684 KB Output is correct
7 Correct 52 ms 4940 KB Output is correct
8 Correct 178 ms 5436 KB Output is correct
9 Correct 10 ms 4648 KB Output is correct
10 Correct 178 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4428 KB Output is correct
2 Correct 3 ms 4428 KB Output is correct
3 Correct 3 ms 4428 KB Output is correct
4 Correct 3 ms 4392 KB Output is correct
5 Correct 3 ms 4432 KB Output is correct
6 Correct 4 ms 4432 KB Output is correct
7 Correct 4 ms 4432 KB Output is correct
8 Correct 4 ms 4392 KB Output is correct
9 Correct 4 ms 4432 KB Output is correct
10 Correct 4 ms 4392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5196 KB Output is correct
2 Correct 8 ms 5324 KB Output is correct
3 Correct 6 ms 5068 KB Output is correct
4 Correct 6 ms 5068 KB Output is correct
5 Correct 9 ms 5420 KB Output is correct
6 Correct 34 ms 4940 KB Output is correct
7 Correct 60 ms 5236 KB Output is correct
8 Correct 86 ms 5196 KB Output is correct
9 Correct 38 ms 4812 KB Output is correct
10 Correct 159 ms 5528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5324 KB Output is correct
2 Correct 8 ms 5324 KB Output is correct
3 Correct 6 ms 5068 KB Output is correct
4 Correct 7 ms 5324 KB Output is correct
5 Correct 7 ms 5196 KB Output is correct
6 Correct 105 ms 5452 KB Output is correct
7 Correct 26 ms 4812 KB Output is correct
8 Correct 75 ms 5212 KB Output is correct
9 Correct 131 ms 5256 KB Output is correct
10 Correct 230 ms 5452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5100 KB Output is correct
2 Correct 6 ms 5068 KB Output is correct
3 Correct 80 ms 5532 KB Output is correct
4 Correct 39 ms 5200 KB Output is correct
5 Correct 33 ms 5564 KB Output is correct
6 Correct 99 ms 6420 KB Output is correct
7 Correct 31 ms 5200 KB Output is correct
8 Correct 36 ms 5312 KB Output is correct
9 Correct 76 ms 5368 KB Output is correct
10 Correct 65 ms 5332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5452 KB Output is correct
2 Correct 9 ms 5452 KB Output is correct
3 Correct 69 ms 5452 KB Output is correct
4 Correct 57 ms 5712 KB Output is correct
5 Correct 31 ms 5684 KB Output is correct
6 Correct 62 ms 5712 KB Output is correct
7 Correct 33 ms 5200 KB Output is correct
8 Correct 100 ms 6096 KB Output is correct
9 Correct 106 ms 5540 KB Output is correct
10 Correct 154 ms 6404 KB Output is correct