Submission #584490

# Submission time Handle Problem Language Result Execution time Memory
584490 2022-06-27T13:06:26 Z Omar_Elgedawy Kronican (COCI16_kronican) C++14
0 / 100
44 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define cin(vec)        for(auto& i : vec) cin >> i
#define cout(vec)       for(auto& i : vec) cout << i << " "; cout << "\n";
#define fast            ios::sync_with_stdio(0);cin.tie(0);
#define loop(i,a,b)     for (int i = a; i < b; i++)
#define F               first
#define S               second
#define pb(n)           push_back(n)
#define pf(n)           push_front(n)
#define dci(d)          fixed<<setprecision(d)
#define sp              ' '
#define el              '\n'
#define all(v)          v.begin(),v.end()
#define int             long long
int dx[8]= {0,0,1,-1,-1,1,1,-1};
int dy[8]= {-1,1,0,0,-1,1,-1,1};
int const N=1e7+5,M=21,Mod=1e9;
int dp[N],k,n,a[M][M];
int rec(int mask){
  if(__builtin_popcount(mask)==k)return 0;
  int &ret=dp[mask];
  if(~ret)return ret;
  ret=1e9;
  for(int i=0;i<n;i++){
    if(!(mask&(1<<i)))continue;
    for(int j=0;j<n;j++){
      if(i==j||!(mask&(1<<j)))continue;
      ret=min(ret,rec(mask^(1<<i))+a[i][j]);
    }
  }
  return ret;
}
void testcase(int h){
  memset(dp,-1,sizeof dp);
  cin>>n>>k;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  cout<<rec((1<<n)-1);
}
int32_t main()
{
  // fast
  testcase(1);
  // int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(i);
  return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 65536 KB Execution killed with signal 9
2 Runtime error 28 ms 65536 KB Execution killed with signal 9
3 Runtime error 28 ms 65536 KB Execution killed with signal 9
4 Runtime error 32 ms 65536 KB Execution killed with signal 9
5 Runtime error 37 ms 65536 KB Execution killed with signal 9
6 Runtime error 32 ms 65536 KB Execution killed with signal 9
7 Runtime error 27 ms 65536 KB Execution killed with signal 9
8 Runtime error 39 ms 65536 KB Execution killed with signal 9
9 Runtime error 44 ms 65536 KB Execution killed with signal 9
10 Runtime error 29 ms 65536 KB Execution killed with signal 9