Submission #884564

# Submission time Handle Problem Language Result Execution time Memory
884564 2023-12-07T16:44:28 Z vjudge1 Kronican (COCI16_kronican) C++17
0 / 100
1043 ms 4516 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int mod = 1e9 + 7;
const int maxn = 20;
const int infinito = 1e9;
int n,k;
int v[maxn][maxn];
int dp[(1<<maxn) + 10];
int contaum(int g){
	int x = 0;
	while(g > 0){
		x++;
		g = g - (g&(-g));
	}
	return x;
}
signed main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		for(int y = 0; y < n; y++){
			cin >> v[i][y];
		}
	}
	for(int i = 0; i <= (1<<n)-1; i++){
		dp[i] = infinito;
	}
	dp[(1<<n)-1] = 0;
	int resul = infinito;
	for(int i = (1<<n)-1; i >= 0; i--){
		int uns = contaum(i);
		for(int y = 0; y < n; y++){
			for(int j = 0; j < n; j++){
				if(j != y){
					if(((i&(1<<j)) >= 1) && ((i&(1<<y)) >= 1)){
						dp[i^(1<<y)] = min(dp[i^(1<<y)],  dp[i] + v[y][j]);
					}
				}
			}
		}
		if(uns <= k){
			//cout << i << "  " << dp[i] << endl;
			resul = min(resul, dp[i]);
		}
		
	}
	cout << resul << endl;
	return 1;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
2 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
3 Runtime error 0 ms 440 KB Execution failed because the return code was nonzero
4 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
5 Runtime error 9 ms 348 KB Execution failed because the return code was nonzero
6 Runtime error 21 ms 568 KB Execution failed because the return code was nonzero
7 Runtime error 46 ms 2652 KB Execution failed because the return code was nonzero
8 Runtime error 100 ms 2648 KB Execution failed because the return code was nonzero
9 Runtime error 1043 ms 4516 KB Execution failed because the return code was nonzero
10 Runtime error 1022 ms 4444 KB Execution failed because the return code was nonzero