# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1101121 | InvMOD | Kronican (COCI16_kronican) | C++14 | 616 ms | 4432 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define siz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 20;
const int inf = 2e6+1;
int n, k, C[N][N];
int dp[(1<<N)];
void solve()
{
cin >> n >> k;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> C[i][j];
}
}
dp[0] = 0;
int answer = inf;
fill(dp+1, dp+(1<<n), inf);
for(int mask = 0; mask < (1<<n); mask++){
if(__builtin_popcount(mask) >= n-k){
answer = min(answer, dp[mask]);
}
else{
for(int i = 0; i < n; i++){
if(!(mask>>i&1)){
for(int j = 0; j < n; j++){
if(i != j && !(mask>>j&1)){
dp[mask^(1<<i)] = min(dp[mask^(1<<i)], dp[mask] + C[i][j]);
}
}
}
}
}
}
cout << answer <<"\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |