Submission #180285

# Submission time Handle Problem Language Result Execution time Memory
180285 2020-01-08T15:23:53 Z awlintqaa Kronican (COCI16_kronican) C++14
100 / 100
1744 ms 8696 KB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 500
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1000000007;//998244353;
const ll inf=1e18*4;
const ld pai=acos(-1);
ll n,k;
ll a[29][29];
ll dp[(1<<20)+9];
ll bt(ll mask,ll crnt){
        if(crnt==k)return 0;
        ll &ret=dp[mask];
        if(ret!=-1)return ret;
        ret=1e18;
        for(ll i=0;i<n;i++){
                for(ll j=0;j<n;j++){
                        if(i==j)C;
                        if((mask&(1<<i)) || (mask&(1<<j)))C;
                        ret=min(ret,bt(mask|(1<<i),crnt-1)+a[i][j]);
                }
        }
        return ret;
}
int main(){
        mem(dp,-1);
        cin>>n>>k;
        for(int i=0;i<n;i++)
                for(int j=0;j<n;j++)
                        cin>>a[i][j];
        cout<<bt(0,n)<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8568 KB Output is correct
2 Correct 9 ms 8440 KB Output is correct
3 Correct 9 ms 8568 KB Output is correct
4 Correct 9 ms 8568 KB Output is correct
5 Correct 21 ms 8696 KB Output is correct
6 Correct 37 ms 8696 KB Output is correct
7 Correct 66 ms 8568 KB Output is correct
8 Correct 142 ms 8696 KB Output is correct
9 Correct 1744 ms 8584 KB Output is correct
10 Correct 146 ms 8572 KB Output is correct