Submission #1101121

# Submission time Handle Problem Language Result Execution time Memory
1101121 2024-10-15T15:17:08 Z InvMOD Kronican (COCI16_kronican) C++14
100 / 100
616 ms 4432 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define gcd __gcd
#define siz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
///#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}

const int N = 20;
const int inf = 2e6+1;

int n, k, C[N][N];
int dp[(1<<N)];

void solve()
{
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> C[i][j];
        }
    }

    dp[0] = 0;
    int answer = inf;
    fill(dp+1, dp+(1<<n), inf);
    for(int mask = 0; mask < (1<<n); mask++){
        if(__builtin_popcount(mask) >= n-k){
            answer = min(answer, dp[mask]);
        }
        else{
            for(int i = 0; i < n; i++){
                if(!(mask>>i&1)){
                    for(int j = 0; j < n; j++){
                        if(i != j && !(mask>>j&1)){
                            dp[mask^(1<<i)] = min(dp[mask^(1<<i)], dp[mask] + C[i][j]);
                        }
                    }
                }
            }
        }
    }
    cout << answer <<"\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}

Compilation message

kronican.cpp: In function 'int main()':
kronican.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 5 ms 536 KB Output is correct
6 Correct 12 ms 592 KB Output is correct
7 Correct 23 ms 2704 KB Output is correct
8 Correct 54 ms 2640 KB Output is correct
9 Correct 616 ms 4432 KB Output is correct
10 Correct 50 ms 4432 KB Output is correct