답안 #88453

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
88453 2018-12-06T01:56:59 Z xiaowuc1 Kronican (COCI16_kronican) C++14
30 / 100
353 ms 788 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> edge;

int dp[20][20];
bool seen[20];

void solve() {
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cin >> dp[i][j];
    }
  }
  int ret = 1 << 30;
  for(int mask = (1<<k)-1; mask < (1<<n); mask++) {
    if(__builtin_popcount(mask) != k) continue;
    int need = n;
    priority_queue<edge> q;
    memset(seen, 0, sizeof(seen));
    {
      int t = mask;
      while(t) {
        int curr = __builtin_ctz(t);
        t &= t-1;
        seen[curr] = true;
        need--;
        for(int i = 0; i < n; i++) {
          if(!(mask&(1<<i))) {
            q.push({-dp[i][curr], i});
          }
        }
      }
    }
    int now = 0;
    while(need && now < ret) {
      edge curr = q.top();
      q.pop();
      if(seen[curr.second]) continue;
      seen[curr.second] = true;
      now -= curr.first;
      need--;
      for(int i = 0; i < n; i++) {
        if(!seen[i]) {
          q.push({-dp[i][curr.second], i});
        }
      }
    }
    ret = min(ret, now);
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Incorrect 2 ms 516 KB Output isn't correct
4 Incorrect 2 ms 516 KB Output isn't correct
5 Incorrect 10 ms 604 KB Output isn't correct
6 Incorrect 8 ms 780 KB Output isn't correct
7 Incorrect 37 ms 780 KB Output isn't correct
8 Incorrect 64 ms 780 KB Output isn't correct
9 Incorrect 17 ms 780 KB Output isn't correct
10 Correct 353 ms 788 KB Output is correct