Submission #201577

#TimeUsernameProblemLanguageResultExecution timeMemory
201577SamAndKronican (COCI16_kronican)C++17
100 / 100
643 ms4480 KiB
#include <bits/stdc++.h> using namespace std; const int N = 22, INF = 1000000009; int n, k; int c[N][N]; int u[N]; int dp[(1 << N)]; int main() { //freopen("input.txt", "r", stdin); scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) scanf("%d", &c[i][j]); } int ans = INF; for (int x = 1; x < (1 << n); ++x) dp[x] = INF; for (int x = 0; x < (1 << n); ++x) { vector<int> v; for (int i = 0; i < n; ++i) { u[i] = INF; if (!(x & (1 << i))) v.push_back(i); } for (int ii = 0; ii < v.size(); ++ii) { int i = v[ii]; for (int jj = 0; jj < v.size(); ++jj) { int j = v[jj]; if (i == j) continue; u[i] = min(u[i], c[i][j]); } } int q = 0; for (int i = 0; i < n; ++i) { if (!(x & (1 << i))) { ++q; dp[(x | (1 << i))] = min(dp[(x | (1 << i))], dp[x] + u[i]); } } if (q == k) ans = min(ans, dp[x]); } printf("%d\n", ans); return 0; }

Compilation message (stderr)

kronican.cpp: In function 'int main()':
kronican.cpp:32:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ii = 0; ii < v.size(); ++ii)
                          ~~~^~~~~~~~~~
kronican.cpp:35:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int jj = 0; jj < v.size(); ++jj)
                              ~~~^~~~~~~~~~
kronican.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
kronican.cpp:18:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &c[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...