Submission #201577

# Submission time Handle Problem Language Result Execution time Memory
201577 2020-02-11T07:24:58 Z SamAnd Kronican (COCI16_kronican) C++17
100 / 100
643 ms 4480 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 22, INF = 1000000009;

int n, k;
int c[N][N];
int u[N];

int dp[(1 << N)];

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
            scanf("%d", &c[i][j]);
    }
    int ans = INF;
    for (int x = 1; x < (1 << n); ++x)
        dp[x] = INF;
    for (int x = 0; x < (1 << n); ++x)
    {
        vector<int> v;
        for (int i = 0; i < n; ++i)
        {
            u[i] = INF;
            if (!(x & (1 << i)))
                v.push_back(i);
        }
        for (int ii = 0; ii < v.size(); ++ii)
        {
            int i = v[ii];
            for (int jj = 0; jj < v.size(); ++jj)
            {
                int j = v[jj];
                if (i == j)
                    continue;
                u[i] = min(u[i], c[i][j]);
            }
        }
        int q = 0;
        for (int i = 0; i < n; ++i)
        {
            if (!(x & (1 << i)))
            {
                ++q;
                dp[(x | (1 << i))] = min(dp[(x | (1 << i))], dp[x] + u[i]);
            }
        }
        if (q == k)
            ans = min(ans, dp[x]);
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

kronican.cpp: In function 'int main()':
kronican.cpp:32:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ii = 0; ii < v.size(); ++ii)
                          ~~~^~~~~~~~~~
kronican.cpp:35:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int jj = 0; jj < v.size(); ++jj)
                              ~~~^~~~~~~~~~
kronican.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
kronican.cpp:18:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &c[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 12 ms 376 KB Output is correct
6 Correct 19 ms 376 KB Output is correct
7 Correct 36 ms 632 KB Output is correct
8 Correct 72 ms 888 KB Output is correct
9 Correct 642 ms 4472 KB Output is correct
10 Correct 643 ms 4480 KB Output is correct