Submission #954488

#TimeUsernameProblemLanguageResultExecution timeMemory
954488GrandTiger1729Netrpeljivost (COI23_netrpeljivost)C++17
59 / 100
1522 ms82732 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int main() { cin.tie(0)->sync_with_stdio(0); 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]; } } if (n == 1) { cout << 0 << '\n'; return 0; } vector<vector<long long>> dp(n, vector<long long>(n, INF)), dp2(n, vector<long long>(n, INF)); function<void(int, int)> solve = [&](int l, int r) { if (l + 2 == r) { dp[l][r - 1] = dp[r - 1][l] = a[l][r - 1]; return; } int mid = (l + r) / 2; solve(l, mid); solve(mid, r); for (int i = l; i < (l + mid) / 2; i++) { for (int j = (l + mid) / 2; j < mid; j++) { for (int k = mid; k < r; k++) { dp2[i][k] = min(dp2[i][k], dp[i][j] + a[j][k]); dp2[j][k] = min(dp2[j][k], dp[j][i] + a[i][k]); } } } for (int i = l; i < mid; i++) { for (int j = mid; j < (mid + r) / 2; j++) { for (int k = (mid + r) / 2; k < r; k++) { dp[i][k] = min(dp[i][k], dp2[i][j] + dp[j][k]); dp[i][j] = min(dp[i][j], dp2[i][k] + dp[k][j]); } } } for (int i = l; i < mid; i++) { for (int j = mid; j < r; j++) { dp[j][i] = min(dp[j][i], dp[i][j]); } } }; solve(0, n); long long ans = INF; for (int i = 0; i < n / 2; i++) { for (int j = n / 2; j < n; j++) { ans = min(ans, dp[i][j]); ans = min(ans, dp[j][i]); } } cout << ans << '\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...