제출 #446887

#제출 시각아이디문제언어결과실행 시간메모리
446887rainboyKronican (COCI16_kronican)C11
100 / 100
162 ms4364 KiB
#include <stdio.h>
#include <string.h>

#define N	20
#define INF	0x3f3f3f3f

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

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

int main() {
	static int aa[N][N], bb[N][N], dp[1 << N];
	int n, k, i, j, b, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &aa[i][j]);
			if (i == j)
				aa[i][j] = INF;
		}
		for (j = n - 1; j >= 0; j--)
			bb[i][j] = min(j + 1 == n ? INF : bb[i][j + 1], aa[i][j]);
	}
	memset(dp, 0x3f, (1 << n) * sizeof *dp), dp[(1 << n) - 1] = 0;
	ans = INF;
	for (b = (1 << n) - 1; b > 0; b--) {
		if (count(b) <= k)
			ans = min(ans, dp[b]);
		for (i = 0; i < n; i++)
			if ((b & 1 << i) != 0)
				dp[b ^ 1 << i] = min(dp[b ^ 1 << i], dp[b] + bb[i][0]);
		j = 0;
		while ((b & 1 << j) == 0)
			j++;
		for (i = 0; i < n; i++)
			bb[i][j] = j + 1 == n ? INF : bb[i][j + 1];
		while (j--)
			for (i = 0; i < n; i++)
				bb[i][j] = min(bb[i][j + 1], aa[i][j]);
	}
	printf("%d\n", ans);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

kronican.c: In function 'count':
kronican.c:10:34: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   10 |  return b == 0 ? 0 : count(b & b - 1) + 1;
      |                                ~~^~~
kronican.c: In function 'main':
kronican.c:17:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
kronican.c:20:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |    scanf("%d", &aa[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...