Submission #1085591

#TimeUsernameProblemLanguageResultExecution timeMemory
1085591CrabCNHKronican (COCI16_kronican)C++14
0 / 100
53 ms17244 KiB
#include <bits/stdc++.h> #define int long long #define pii pair <int, int> #define fi first #define se second using namespace std; const int N = 20 + 5; const int inf = 1e18 + 7; int n, k; int c[N][N]; int dp[1 << 20]; void read () { #define task "crab" if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } } bool bit (int x, int i) { return ((x >> i) & 1); } int flip (int x, int i) { return (x | (1 << i)); } signed main () { ios_base :: sync_with_stdio (0); cin.tie (0); read (); cin >> n >> k; for (int i = 1; i <= n; i ++) { for (int j = 1; j <= n; j ++) { cin >> c[i][j]; } } memset(dp, 0x3f, sizeof dp); int ans = dp[0]; dp[(1 << n) - 1] = 0; for (int x = (1 << n) - 1; x >= 0; x --) { for (int i = 1; i <= n; i ++) { if (bit(x, i - 1)) { int y = flip (x, i); int cost = inf; for (int j = 1; j <= n; j ++) { if (bit (y, j - 1)) { cost = min(cost, c[i][j]); } } dp[y] = min(dp[y], dp[x] + cost); } } } for (int mask = 1; mask < (1 << n); mask ++) { if (__builtin_popcount(mask) <= k) ans = min(ans, dp[mask]); } cout << ans; }

Compilation message (stderr)

kronican.cpp: In function 'void read()':
kronican.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:21:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...