Submission #98490

# Submission time Handle Problem Language Result Execution time Memory
98490 2019-02-23T18:58:16 Z pamaj Kronican (COCI16_kronican) C++17
90 / 100
2000 ms 4520 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;

#pragma GCC optimize ("Ofast")

int n, k;
int c[maxn][maxn];
int dp[1 << 20];

int solve(const int& mask)
{
	if(__builtin_popcount(mask) <= k) return 0;

	if(dp[mask] != -1) return dp[mask];

	int ans = 1e7;

	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 dp[mask] = ans;
}


int32_t main()
{	
	ios::sync_with_stdio(false), cin.tie(nullptr);
	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((1 << n) - 1) << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4480 KB Output is correct
2 Correct 5 ms 4480 KB Output is correct
3 Correct 6 ms 4480 KB Output is correct
4 Correct 6 ms 4480 KB Output is correct
5 Correct 19 ms 4480 KB Output is correct
6 Correct 37 ms 4480 KB Output is correct
7 Correct 79 ms 4484 KB Output is correct
8 Correct 157 ms 4480 KB Output is correct
9 Execution timed out 2043 ms 4480 KB Time limit exceeded
10 Correct 183 ms 4520 KB Output is correct