답안 #627503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627503 2022-08-12T15:55:02 Z MilosMilutinovic Kronican (COCI16_kronican) C++14
100 / 100
648 ms 4392 KB
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9;

int n, k, c[20][20], dp[1 << 20];
int main()
{
	scanf("%d%d", &n, &k);
	rep(i, n) rep(j, n) scanf("%d", &c[i][j]);
	rep(i, 1 << n) dp[i] = INF;
	dp[(1 << n) - 1] = 0;
	for(int mask = (1 << n) - 1; mask >= 0; mask --) {
		rep(i, n) if(mask >> i & 1) {
			int mn = INF;
			rep(j, n) if(i != j && (mask >> j & 1)) mn = min(mn, c[i][j]);
			dp[mask ^ (1 << i)] = min(dp[mask ^ (1 << i)], dp[mask] + mn);
		}
	}
	int ans = INF;
	rep(i, (1 << n)) if(__builtin_popcount(i) == k) ans = min(ans, dp[i]);
	printf("%d", ans);
	return 0;
}

Compilation message

kronican.cpp: In function 'int main()':
kronican.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
kronican.cpp:15:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  rep(i, n) rep(j, n) scanf("%d", &c[i][j]);
      |                      ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Correct 14 ms 440 KB Output is correct
7 Correct 32 ms 568 KB Output is correct
8 Correct 67 ms 820 KB Output is correct
9 Correct 637 ms 4388 KB Output is correct
10 Correct 648 ms 4392 KB Output is correct