Submission #201576

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

int n, k;
int c[N][N];
int u[(1 << N)][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]);
    }
    for (int x = 0; x < (1 << n); ++x)
    {
        vector<int> v;
        for (int i = 0; i < n; ++i)
        {
            u[x][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[x][i] = min(u[x][i], 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)
    {
        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[x][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:29:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ii = 0; ii < v.size(); ++ii)
                          ~~~^~~~~~~~~~
kronican.cpp:32: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 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 13 ms 1788 KB Output is correct
6 Correct 21 ms 3320 KB Output is correct
7 Correct 42 ms 6264 KB Output is correct
8 Correct 77 ms 12280 KB Output is correct
9 Runtime error 483 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 478 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)