Submission #98539

# Submission time Handle Problem Language Result Execution time Memory
98539 2019-02-23T22:03:52 Z pamaj Kronican (COCI16_kronican) C++14
20 / 100
2000 ms 8696 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
#define int uint_fast32_t
 
#pragma GCC optimize ("Ofast")
 
int n, k;
int c[maxn][maxn];
int dp[1 << 20];
 
int solve(int mask)
{
	if(__builtin_popcount(mask) >= n - k) return 0;
 
	if(dp[mask] != -1) return dp[mask];
 
	int ans = dp[mask];
  
  	ans = 1e9;
  
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(i == j or (mask & (1 << i)) or (mask & (1 << j))) continue;
 
			ans = min(ans, solve(mask | (1 << i)) + c[i][j]);
		}
	}
 
	return ans;
}
 
 
int32_t main()
{
	cin >> n >> k;
 
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
			cin >> c[i][j];
	}
 
	memset(dp, -1, sizeof(dp));
 
	cout << solve(0) << "\n";
 
}

Compilation message

kronican.cpp: In function 'uint_fast32_t solve(uint_fast32_t)':
kronican.cpp:16:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(dp[mask] != -1) return dp[mask];
     ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8576 KB Output is correct
2 Correct 283 ms 8696 KB Output is correct
3 Execution timed out 2029 ms 8576 KB Time limit exceeded
4 Execution timed out 2060 ms 8576 KB Time limit exceeded
5 Execution timed out 2052 ms 8576 KB Time limit exceeded
6 Execution timed out 2054 ms 8448 KB Time limit exceeded
7 Execution timed out 2057 ms 8576 KB Time limit exceeded
8 Execution timed out 2045 ms 8576 KB Time limit exceeded
9 Execution timed out 2068 ms 8448 KB Time limit exceeded
10 Execution timed out 2060 ms 8448 KB Time limit exceeded