Submission #447339

# Submission time Handle Problem Language Result Execution time Memory
447339 2021-07-26T06:37:13 Z XBoRickie Kronican (COCI16_kronican) C++11
100 / 100
805 ms 4364 KB
#include <bits/stdc++.h>
using namespace std;
// Typedef
typedef long double                ld;
typedef long long int              int64;
typedef unsigned long long int     uint64;
typedef std::pair<int, int>        PII;
typedef std::pair<int64, int64>    PLL;
typedef std::vector<int>           VI;
typedef std::vector<long long>     VLL;
// Define For-loop
#define FOR(i, j, k, in)           for (int i = (j); i < (k) ; i += (in))
#define FORW(i, j, k, in)          for (int i = (j); i <= (k); i += (in))
#define RFOR(i, j, k, in)          for (int i = (j); i >= (k); i -= (in))
// Define Data structure func
#define all(cont)                  cont.begin(), cont.end()
#define rall(cont)                 cont.rbegin(), cont.rend()
#define sz(cont)                   int((cont).size())
#define pb                         push_back
#define mp                         make_pair
#define fi                         first
#define se                         second
// Define number
#define IINF                       0x3f3f3f3f
#define LLINF                      1000111000111000111LL
#define PI                         3.1415926535897932384626433832795
// Other
#define lend                       '\n'
#define hardio(name)               freopen(name".inp","r",stdin), freopen(name".out","w",stdout);
void FastIO() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin.exceptions(cin.failbit); srand(time(NULL)); }

const int MOD = 1e9 + 7, MOD2 = 1e9 + 9;
// ======================================================================

int n, k;
int a[30][30] = {};
int dp[1 << 20] = {};


int main(int argc, char* argv[]) {
    FastIO();

    cin >> n >> k;
    FOR(i, 0, n, 1) FOR(j, 0, n, 1) cin >> a[i][j];

    RFOR(mask, (1 << n) - 1, 0, 1) {
        dp[mask] = IINF;
        int cnt = 0;
        FOR(i, 0, n, 1) {
            if ((mask & (1 << i))) continue;
            int mn = IINF;
            FOR(j, 0, n, 1) {
                if ((mask & (1 << j)) || i == j) continue;
                mn = min(mn, a[i][j]);
            }
            dp[mask] = min(dp[mask], dp[mask | (1 << i)] + mn);
            ++cnt;
        }
        if (cnt <= k) dp[mask] = 0;
    }

    cout << dp[0] << endl;

    return 0; }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 8 ms 332 KB Output is correct
6 Correct 18 ms 408 KB Output is correct
7 Correct 36 ms 576 KB Output is correct
8 Correct 77 ms 804 KB Output is correct
9 Correct 779 ms 4296 KB Output is correct
10 Correct 805 ms 4364 KB Output is correct