Submission #222005

#TimeUsernameProblemLanguageResultExecution timeMemory
222005Haunted_CppKronican (COCI16_kronican)C++17
100 / 100
1065 ms4496 KiB
/* 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; int A = mask ^ (1 << i); int B = mask ^ (1 << j); res = min (res, g[i][j] + dfs (A)); res = min (res, g[j][i] + dfs (B)); } } 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 timeMemoryGrader output
Fetching results...