Submission #89150

# Submission time Handle Problem Language Result Execution time Memory
89150 2018-12-10T15:43:08 Z asifthegreat Kronican (COCI16_kronican) C++14
100 / 100
1723 ms 4708 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 20;

int n,k;
int ara[N][N];
int dp[1<<N];

bool check(int mask,int number){return mask&(1<<number);}
int Set(int mask,int number){return mask = mask^(1<<number);}

int call(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(!check(mask,i))continue;
        for(int j = 0; j < n;j++){
            if(i == j or !check(mask,j))continue;
            ret = min(ret,call(Set(mask,j))+ara[j][i]);
        }
    }
    return ret;
}

int main()
{
    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",&ara[i][j]);
        }
    }
    printf("%d\n",call((1<<n)-1));

    return 0;
}

Compilation message

kronican.cpp: In function 'int main()':
kronican.cpp:32: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:35:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&ara[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4344 KB Output is correct
2 Correct 5 ms 4596 KB Output is correct
3 Correct 5 ms 4600 KB Output is correct
4 Correct 6 ms 4600 KB Output is correct
5 Correct 17 ms 4600 KB Output is correct
6 Correct 34 ms 4628 KB Output is correct
7 Correct 64 ms 4628 KB Output is correct
8 Correct 146 ms 4708 KB Output is correct
9 Correct 1723 ms 4708 KB Output is correct
10 Correct 157 ms 4708 KB Output is correct