# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222006 | Haunted_Cpp | Kronican (COCI16_kronican) | C++17 | 1059 ms | 4480 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
author: Haunted_Cpp
"Persistence guarantees that results are inevitable"
*/
#include <iostream>
#include <algorithm>
#include <vector>
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 20 + 1;
int dp [1 << N], g [N][N], n, k;
int dfs (int mask) {
if (__builtin_popcount(mask) <= k) return 0;
int &res = dp[mask];
if (res) return res;
res = 1e9;
for (int i = 0; i < n; i++) {
if (((mask >> i) & 1) == 0) continue;
for (int j = i + 1; j < n; j++) {
if (((mask >> j) & 1) == 0) continue;
res = min (res, g[i][j] + dfs (mask ^ (1 << i)));
res = min (res, g[j][i] + dfs (mask ^ (1 << j)));
}
}
return res;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> g[i][j];
}
}
cout << dfs ((1 << n) - 1) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |