답안 #1114267

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114267 2024-11-18T13:20:58 Z ljtunas Kronican (COCI16_kronican) C++14
100 / 100
1014 ms 8528 KB
#include <bits/stdc++.h>

using namespace std;

#define db  double
#define pb  push_back
#define ll  long long
#define int long long
#define ii  pair<int, int>
#define fi  first
#define se  second
#define vi  vector <int>
#define vvi  vector <vi>
#define vvvi  vector <vvi>
#define vii vector<ii>
#define sqrt sqrtl
#define FORV(v, H)     for(auto &v: H)
#define FOR(i, a, b)   for(int i=a;i<=b;++i)
#define FORD(i, a, b)  for(int i=a;i>=b;--i)
#define BIT(mask, i)   ((mask >> i) & 1LL)
#define ONBIT(mask, i) (mask | (1LL << i))
#define OFFBIT(mask, i) (mask &~ (1LL << i))
#define cnt_BIT(i)   __builtin_popcountll(i)

#define task "kronican"

const int MAXN = 20  + 10;
const int   oo = 1e9 + 8;
const int  MOD = 1e9 + 7;

int N, K;
int C[MAXN][MAXN];
vi dp;
int dis[MAXN][MAXN];

int solve(int mask) {
//    cerr << mask << '\n';
    if (cnt_BIT(mask) <= K) {
        return 0;
    }
    if (dp[mask] != -1)
        return dp[mask];
    int cur = +oo;
    FOR(i, 1, N) {
        if (BIT(mask, i - 1) == 1)
        FOR(j, 1, N) {
            if (i != j && BIT(mask, j - 1) == 1) {
                int newmask = OFFBIT(mask, i - 1);
                newmask = ONBIT(newmask, j - 1);
                cur = min(cur, solve(newmask) + C[i][j]);
            }
        }
    }
    return dp[mask] = cur;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    if (ifstream(task".inp")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin >> N >> K;
    FOR(i, 1, N) FOR(j, 1, N) {
        cin >> C[i][j];
    }

    dp.assign((1 << N) + 5, -1);

    cout << solve((1 << N) - 1) << '\n';
//    cout << (1 << N) - 1 << '\n';
    return 0;

}

Compilation message

kronican.cpp: In function 'long long int solve(long long int)':
kronican.cpp:45:25: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   45 |         if (BIT(mask, i - 1) == 1)
      |                       ~~^~~
kronican.cpp:20:34: note: in definition of macro 'BIT'
   20 | #define BIT(mask, i)   ((mask >> i) & 1LL)
      |                                  ^
kronican.cpp:47:39: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   47 |             if (i != j && BIT(mask, j - 1) == 1) {
      |                                     ~~^~~
kronican.cpp:20:34: note: in definition of macro 'BIT'
   20 | #define BIT(mask, i)   ((mask >> i) & 1LL)
      |                                  ^
kronican.cpp:48:46: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   48 |                 int newmask = OFFBIT(mask, i - 1);
      |                                            ~~^~~
kronican.cpp:22:42: note: in definition of macro 'OFFBIT'
   22 | #define OFFBIT(mask, i) (mask &~ (1LL << i))
      |                                          ^
kronican.cpp:49:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   49 |                 newmask = ONBIT(newmask, j - 1);
      |                                          ~~^~~
kronican.cpp:21:40: note: in definition of macro 'ONBIT'
   21 | #define ONBIT(mask, i) (mask | (1LL << i))
      |                                        ^
kronican.cpp: In function 'int main()':
kronican.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 472 KB Output is correct
5 Correct 8 ms 592 KB Output is correct
6 Correct 18 ms 764 KB Output is correct
7 Correct 34 ms 848 KB Output is correct
8 Correct 77 ms 1360 KB Output is correct
9 Correct 1014 ms 8528 KB Output is correct
10 Correct 88 ms 8528 KB Output is correct