답안 #89151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89151 2018-12-10T15:43:52 Z asifthegreat Kronican (COCI16_kronican) C++14
20 / 100
2000 ms 4688 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]);
             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4472 KB Output is correct
2 Correct 237 ms 4568 KB Output is correct
3 Execution timed out 2004 ms 4568 KB Time limit exceeded
4 Execution timed out 2033 ms 4568 KB Time limit exceeded
5 Execution timed out 2068 ms 4568 KB Time limit exceeded
6 Execution timed out 2033 ms 4568 KB Time limit exceeded
7 Execution timed out 2025 ms 4568 KB Time limit exceeded
8 Execution timed out 2045 ms 4644 KB Time limit exceeded
9 Execution timed out 2025 ms 4688 KB Time limit exceeded
10 Execution timed out 2048 ms 4688 KB Time limit exceeded