Submission #367453

# Submission time Handle Problem Language Result Execution time Memory
367453 2021-02-17T12:24:16 Z FatihSolak Kronican (COCI16_kronican) C++17
100 / 100
416 ms 4588 KB
#include <bits/stdc++.h>
#define N 20
using namespace std;
int dist[N][N];
int dp[(1<<N)];
void solve(){
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> dist[i][j];
        }
    }
    for(int i=1;i<(1<<n);i++){
        dp[i] = 1e9;
    }
    int ans = 1e9;
    for(int i=0;i<(1<<n);i++){
        vector<int> un;
        for(int j=0;j<n;j++){
            if(!(i & (1<<j))){
                un.push_back(j);
            }
        }
        if(un.size() == k){
            ans = min(ans,dp[i]);
        }
        for(auto u:un){
            int mini = 1e9;
            for(auto v:un){
                if(u == v)continue;
                mini = min(mini,dist[u][v]);
            }
            dp[i+(1<<u)] = min(dp[i+(1<<u)],dp[i]+mini);
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message

kronican.cpp: In function 'void solve()':
kronican.cpp:25:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         if(un.size() == k){
      |            ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 5 ms 364 KB Output is correct
6 Correct 10 ms 492 KB Output is correct
7 Correct 21 ms 620 KB Output is correct
8 Correct 44 ms 876 KB Output is correct
9 Correct 397 ms 4588 KB Output is correct
10 Correct 416 ms 4500 KB Output is correct