# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
709464 | 2023-03-13T16:07:22 Z | TAhmed33 | Kronican (COCI16_kronican) | C++ | 1240 ms | 8496 KB |
#include <bits/stdc++.h> using namespace std; #define int long long int n, k; int effort[20][20]; int dp[(1 << 20)] = {}; int ans (int mask) { if (__builtin_popcount(mask) == k) return 0; int &ret = dp[mask]; if (ret != -1) return ret; vector <int> bits; for (int i = 0; i < n; i++) if (mask & (1 << i)) bits.push_back(i); int u = 1e9; for (int i = 0; i < bits.size(); i++) { for (int j = i + 1; j < bits.size(); j++) { u = min(u, effort[bits[i]][bits[j]] + ans(mask ^ (1 << bits[i]))); u = min(u, effort[bits[j]][bits[i]] + ans(mask ^ (1 << bits[j]))); } } return ret = u; } signed main () { memset(dp, -1, sizeof(dp)); cin >> n >> k; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> effort[i][j]; cout << ans((1 << n) - 1) << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8404 KB | Output is correct |
2 | Correct | 4 ms | 8404 KB | Output is correct |
3 | Correct | 4 ms | 8404 KB | Output is correct |
4 | Correct | 4 ms | 8404 KB | Output is correct |
5 | Correct | 13 ms | 8404 KB | Output is correct |
6 | Correct | 26 ms | 8404 KB | Output is correct |
7 | Correct | 41 ms | 8404 KB | Output is correct |
8 | Correct | 93 ms | 8404 KB | Output is correct |
9 | Correct | 1240 ms | 8496 KB | Output is correct |
10 | Correct | 115 ms | 8404 KB | Output is correct |