Submission #1131664

#TimeUsernameProblemLanguageResultExecution timeMemory
1131664HectonitNetrpeljivost (COI23_netrpeljivost)C++20
100 / 100
286 ms49872 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll infl = 1e18; void solve() { int n; cin >> n; vector<vector<int>> a(n, vector<int> (n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } vector<vector<ll>> dp(n, vector<ll> (n, infl)); for (int i = 0; i < n; i++) { dp[0][i] = 0; } for (int i = 0; i < n - 1; i++) { int pr = i + 1, bsz = 1; for (int j = 0; j < 15; j++) { if (pr & 1) { bsz = (1 << j); break; } pr >>= 1; } for (int j = 0; j < n; j++) { if (dp[i][j] == infl) continue; int k = j ^ bsz; k -= k & (bsz - 1); for (int l = 0; l < bsz; l++) { dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + a[j][k]); k++; } } } ll ans = infl; for (int i = 0; i < n; i++) { ans = min(ans, dp[n - 1][i]); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...