# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642529 | Urvuk3 | Kronican (COCI16_kronican) | C++17 | 724 ms | 8532 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=20,MAXA=5e6+5,INF=1e9;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),a.end()
#define mod 1000000007LL
#define pb push_back
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define PRINTBITS(x) {bitset<5> f=x; cerr<<#x<<'-'<<f<<endl<<flush;}
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
ll n,m,k,q,x,y,z,res=INF,l,r;
string s,t;
vector<int> a;
ifstream in;
#ifdef ONLINE_JUDGE
#define in cin
#endif
vector<ll> dp((1<<MAXN),INF);
int c[MAXN][MAXN];
void solve(){
cin>>n>>k;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>c[i][j];
}
}
dp[(1<<n)-1]=0; // sve su pune
for(int m1=(1<<n)-1;m1>=0;m1--){ // 1 ako je casa puna
for(int i=0;i<n;i++){ // i-ta casa je puna m1&(1<<i)
for(int j=0;j<n;j++){ // j-ta casa je puna m1&(1<<j)
if(m1&(1<<i) && m1&(1<<j) && i!=j){
ll m2=m1^(1<<i); // i-ta postaje prazna
dp[m2]=min(dp[m2],dp[m1]+c[i][j]);
}
}
}
}
for(int m1=(1<<n)-1;m1>=0;m1--){
if(__builtin_popcount(m1)<=k){
res=min(res,dp[m1]);
}
}
cout<<res<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
in.open("D:\\UROS\\Programiranje\\input.in",ios::in);
#endif
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int t;
//cin>>t;
t=1;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |