This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
#endif // LOCAL
int N;
cin >> N;
vector<vector<int>> cost(N, vector<int>(N, 0));
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j){
cin >> cost[i][j];
}
}
const long long inf = 1e18;
vector<long long> f(N, 0);
int full = N - 1;
for(int i = 1; i < N; ++i){
vector<long long> g(N, inf);
int lsb = i & (-i);
for(int j = 0; j < N; ++j){
int t = (j ^ lsb) & (full ^ (lsb - 1));
for(int last = t; last < t + lsb; ++last){
g[j] = min(g[j], f[last] + cost[last][j]);
}
}
f = g;
}
long long ans = *min_element(f.begin(), f.end());
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |