# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
243431 | VEGAnn | Kronican (COCI16_kronican) | C++14 | 746 ms | 4576 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
using namespace std;
const int N = 20;
const int oo = 2e9;
int a[N][N], ans = oo, n, k, f[(1 << N)];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
fill(f, f + (1 << n), oo);
f[(1 << n) - 1] = 0;
for (int msk = (1 << n) - 1; msk > 0; msk--)
if (__builtin_popcount(msk) <= k){
ans = min(ans, f[msk]);
} else {
for (int fr = 0; fr < n; fr++)
if (msk & (1 << fr)){
int nw = (msk ^ (1 << fr));
for (int wh = 0; wh < n; wh++)
if (nw & (1 << wh))
f[nw] = min(f[nw], f[msk] + a[fr][wh]);
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |