Submission #883673

# Submission time Handle Problem Language Result Execution time Memory
883673 2023-12-05T16:36:56 Z vjudge1 Kronican (COCI16_kronican) C++17
100 / 100
644 ms 8788 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=2e5+100;
#else
    const int lim=1e3+100;
#endif

#include "bits/stdc++.h"
using namespace std;

#define int long long
#define pb push_back

const int mod=1e9+7;
using pii=pair<int,int>;

inline void solve(){
    int n,k;
    cin>>n>>k;
    int a[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    int inf=INT_MAX*100ll;
    int ans=inf;
    int dp[1<<n];
    for(int i=0;i<(1<<n);i++)dp[i]=inf;
    dp[(1<<n)-1]=0;
    for(int m=(1<<n)-1;m;m--){
        //cerr<<(bitset<5>(m))<<" "<<dp[m]<<"\n";
        for(int i=0;i<n;i++){
            if(m&(1<<i)){
                for(int j=0;j<n;j++){
                    if(m&(1<<j)&&(i^j)){
                        //cerr<<"update "<<(bitset<5>(m^(1<<i)))<<" "<<dp[m]+a[i][j]<<"\n";
                        dp[m^(1<<i)]=min(dp[m^(1<<i)],dp[m]+a[i][j]);
                    }
                }
            }
        }
        if(__popcount(m)<=k){
            ans=min(ans,dp[m]);
        }
    }
    cout<<ans<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    //freopen("grass.in","r",stdin);
    //freopen("grass.out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 6 ms 348 KB Output is correct
6 Correct 13 ms 700 KB Output is correct
7 Correct 31 ms 856 KB Output is correct
8 Correct 62 ms 1368 KB Output is correct
9 Correct 633 ms 8632 KB Output is correct
10 Correct 644 ms 8788 KB Output is correct