Submission #973449

# Submission time Handle Problem Language Result Execution time Memory
973449 2024-05-02T02:38:08 Z modwwe Kronican (COCI16_kronican) C++17
100 / 100
708 ms 8656 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define ii pair<int,int>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pb push_back
#define sz(a) (int)(a.size())
#define on(n) __builtin_popcountll(n)
#define ld long double
#define bit(i,j) ((i>>j)&1)
#define oo INT_MAX
const int N=25;
ll n,dp[(1<<20)],c[N][N],k;
void solution(){
   cin >> n >> k;
   rep(i,1,n){
      rep(j,1,n) cin >> c[i][j];
   }
   memset(dp,0x3f,sizeof(dp));
   dp[(1<<n)-1]=0;
   rev(mask,(1<<n)-1,0){
      rep(j,0,n-1){
         if (bit(mask,j)){
            ll premask=(mask^(1<<j));
            ll cost=1e18;
            rep(z,0,n-1){
               if (bit(premask,z)) cost=min(cost,c[j+1][z+1]);
            }
            dp[premask]=min(dp[premask],dp[mask]+cost);
         }
      }
   }
   ll res=1e18;
   rep(i,0,(1<<n)-1){
      if (on(i)==k){
        res=min(res,dp[i]);
      }
   }
   cout << res;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t--) solution();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 8536 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 10 ms 8540 KB Output is correct
6 Correct 16 ms 8540 KB Output is correct
7 Correct 32 ms 8656 KB Output is correct
8 Correct 68 ms 8644 KB Output is correct
9 Correct 708 ms 8540 KB Output is correct
10 Correct 679 ms 8648 KB Output is correct