Submission #1108104

# Submission time Handle Problem Language Result Execution time Memory
1108104 2024-11-02T18:34:30 Z overwatch9 Kronican (COCI16_kronican) C++17
30 / 100
322 ms 4432 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    vector <vector <int>> adj(n, vector <int> (n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cin >> adj[i][j];
    }
    vector <int> dp((1 << n) + 1, 1e9);
    dp[0] = 0;
    int ans = 1e9;
    for (int i = 0; i < (1 << n); i++) {
        if (__builtin_popcount(i) <= 1) {
            dp[i] = 0;
            if (__builtin_popcount(i) == n-k+1)
                ans = 0;
            continue;
        }
        vector <int> ls;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j))
                ls.push_back(j);
        }
        for (auto j : ls) {
            for (auto k : ls) {
                if (j == k)
                    continue;
                dp[i] = min(dp[i], dp[i ^ (1 << j)] + adj[j][k]);
            }
        }
        if (__builtin_popcount(i) == n-k+1)
            ans = min(ans, dp[i]);
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 4 ms 336 KB Output isn't correct
6 Incorrect 8 ms 336 KB Output isn't correct
7 Incorrect 14 ms 760 KB Output isn't correct
8 Incorrect 28 ms 952 KB Output isn't correct
9 Incorrect 307 ms 4432 KB Output isn't correct
10 Incorrect 322 ms 4432 KB Output isn't correct