Submission #1241651

#TimeUsernameProblemLanguageResultExecution timeMemory
1241651hainam2k9Kronican (COCI16_kronican)C++20
100 / 100
470 ms4544 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = (1<<20)+5;
const string NAME = "";
int n,k,cost[25][25],dp[MAXN],rs=1e9;
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> k;
    for(int i = 0; i<n; ++i)
        for(int j = 0; j<n; ++j)
            cin >> cost[i][j];
    memset(dp,0x3f,sizeof(dp));
    for(int mask = 1; mask<(1<<n); ++mask){
        if(__builtin_popcount(mask)<k) continue;
        if(__builtin_popcount(mask)==k) dp[mask]=0;
        for(int i = 0; i<n; ++i)
            if(!((mask>>i)&1))
                for(int j = 0; j<n; ++j)
                    if((mask>>j)&1) dp[mask|(1<<i)]=min(dp[mask|(1<<i)],dp[mask]+cost[i][j]);
    }
    cout << dp[(1<<n)-1];
}

Compilation message (stderr)

kronican.cpp: In function 'int main()':
kronican.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:26:45: note: in expansion of macro 'fo'
   26 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
kronican.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:26:45: note: in expansion of macro 'fo'
   26 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...