# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98555 | 2019-02-24T03:04:12 Z | pamaj | Kronican (COCI16_kronican) | C++14 | 2000 ms | 8600 KB |
#include <cstdio> #include <string> #include <vector> #include <map> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; typedef long long llint; typedef pair <int, int> pii; const int MAXN = 21; int n, k; int a[MAXN][MAXN]; int dp[1 << MAXN]; int solve(int mask) { if (__builtin_popcount(mask) == k) return 0; int &ret = dp[mask]; if (ret != -1) return ret; ret = 1 << 30; for (int i = 0; i < n; ++i) { if (!(mask & (1 << i)) ) continue; for (int j = 0; j < n; ++j) { if (i == j) continue; if (!(mask & (1 << j))) continue; ret = min(ret, solve(mask ^ (1 << i)) + a[i][j]); } } return ret; } int main (void){ memset(dp, -1, sizeof dp); scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]); printf("%d\n", solve((1 << n) - 1)); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8448 KB | Output is correct |
2 | Correct | 9 ms | 8548 KB | Output is correct |
3 | Correct | 10 ms | 8448 KB | Output is correct |
4 | Correct | 10 ms | 8448 KB | Output is correct |
5 | Correct | 17 ms | 8448 KB | Output is correct |
6 | Correct | 41 ms | 8568 KB | Output is correct |
7 | Correct | 83 ms | 8548 KB | Output is correct |
8 | Correct | 154 ms | 8548 KB | Output is correct |
9 | Execution timed out | 2025 ms | 8548 KB | Time limit exceeded |
10 | Correct | 187 ms | 8600 KB | Output is correct |