# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
88453 | xiaowuc1 | Kronican (COCI16_kronican) | C++14 | 353 ms | 788 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |