Submission #98456

# Submission time Handle Problem Language Result Execution time Memory
98456 2019-02-23T17:52:51 Z thiago4532 Kronican (COCI16_kronican) C++17
20 / 100
2000 ms 4480 KB
#include <bits/stdc++.h>
// #define int int64_t

using namespace std;
const int maxn = 30;
int c[maxn][maxn];
int dp[1<<(maxn-10)];
int n, k;

int solve(int mask){
	if(n - __builtin_popcount(mask) == k) return 0;
	//cout << bitset<10>(mask) << "\n";
	int ans=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		if(mask&(1<<(i-1))) continue;

		for(int j=1;j<=n;j++){
			if(i==j || mask&(1<<(j-1))) continue;
			int mask2 = mask | (1<<(i-1));
			ans = min(ans, c[i][j] + solve(mask2));
		}
	}
	return dp[mask] = ans;
}

int32_t main(){
	//memset(c, 0x3f3f3f3f, sizeof c);
	memset(dp, -1, sizeof dp);
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin >> c[i][j];
		}
	}
	cout << solve(0) << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4352 KB Output is correct
2 Correct 216 ms 4480 KB Output is correct
3 Execution timed out 2045 ms 4352 KB Time limit exceeded
4 Execution timed out 2101 ms 4480 KB Time limit exceeded
5 Execution timed out 2045 ms 4352 KB Time limit exceeded
6 Execution timed out 2021 ms 4352 KB Time limit exceeded
7 Execution timed out 2041 ms 4480 KB Time limit exceeded
8 Execution timed out 2045 ms 4352 KB Time limit exceeded
9 Execution timed out 2013 ms 4352 KB Time limit exceeded
10 Execution timed out 2051 ms 4480 KB Time limit exceeded