Submission #167146

# Submission time Handle Problem Language Result Execution time Memory
167146 2019-12-06T06:36:52 Z sans Kronican (COCI16_kronican) C++11
100 / 100
1756 ms 8572 KB
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAXN = 21;
int N, K, dp[1 << MAXN], a[MAXN][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(int argc, char **argv){
    scanf("%d %d", &N, &K);

    memset(dp, -1, sizeof dp);
    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;
}

//cikisir

Compilation message

kronican.cpp: In function 'int main(int, char**)':
kronican.cpp:28: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:33:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8440 KB Output is correct
2 Correct 9 ms 8568 KB Output is correct
3 Correct 10 ms 8568 KB Output is correct
4 Correct 10 ms 8572 KB Output is correct
5 Correct 21 ms 8568 KB Output is correct
6 Correct 38 ms 8440 KB Output is correct
7 Correct 67 ms 8568 KB Output is correct
8 Correct 146 ms 8552 KB Output is correct
9 Correct 1756 ms 8568 KB Output is correct
10 Correct 160 ms 8568 KB Output is correct