제출 #1187418

#제출 시각아이디문제언어결과실행 시간메모리
1187418vitoNetrpeljivost (COI23_netrpeljivost)C++20
10 / 100
3 ms328 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define F first
#define S second
#define sz(x) int(x.size())
const int MAX=2100;
const ll INF=1e18+5;
int f[MAX][MAX], n;
int mask, L;
vector<int> a;
void nap(int x) {
	if(x>L) {
		a.push_back(x-n+1);
		return;
	}
	if(mask&(1<<(x-1))) {
		nap(2*x+1);
		nap(2*x);
	}
	else {
		nap(2*x);
		nap(2*x+1);
	}
}
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	if(n>16) {
		return 5;
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			cin >> f[i][j];
		}
	}
	ll out=INF;
	L=n-1;
	for(mask=0; mask<(1<<L); mask++) {
		a={};
		nap(1);
		ll c=0;
		for(int i=1; i<n; i++) {
			c+=f[a[i-1]][a[i]];
		}
		out=min(out, c);
	}
	cout << out << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...