Submission #373108

#TimeUsernameProblemLanguageResultExecution timeMemory
373108maozkurtKronican (COCI16_kronican)C++17
100 / 100
1268 ms4588 KiB
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <ctime> #include <iostream> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #include <string> #include <stack> #include <numeric> #include <cassert> #define endl '\n' #define sp ' ' #define pb push_back #define mp make_pair #define ff first #define ss second using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn = 25; const int inf = 1e9; int c[maxn][maxn]; int dp[1<<20]; int popcount(int n){ int ret = 0; while(n){ if(n&1) ret++; n>>=1; } return ret; } int n,k; int f(int mask){ if(dp[mask] != -1) return dp[mask]; if(popcount(mask) == k) return 0; int ret = inf; for(int i=0;i<n;i++){ if(mask & (1<<i)){ for(int j=0;j<n;j++){ if(i==j) continue; if(mask & (1<<j)){ ret = min(ret,f(mask ^ (1<<i)) + c[i][j]); } } } } return dp[mask] = ret; } int main(){ ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr); memset(dp,-1,sizeof dp); cin>>n>>k; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>c[i][j]; cout << f((1<<n)-1) << endl; }

Compilation message (stderr)

kronican.cpp: In function 'int f(int)':
kronican.cpp:49:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   49 |     if(popcount(mask) == k)
      |     ^~
kronican.cpp:50:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   50 |         return 0;   int ret = inf;
      |                     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...