Submission #1059679

#TimeUsernameProblemLanguageResultExecution timeMemory
1059679NeroZeinNetrpeljivost (COI23_netrpeljivost)C++17
0 / 100
1 ms348 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define debug(...) #endif const int N = 2050; const long long INF = 1e16; int a[N][N]; long long dp[N][N]; void build(int nd, int l, int r) { if (l == r) { return; } int mid = (l + r) >> 1; build(nd * 2, l, mid); build(nd * 2 + 1, mid + 1, r); for (int i = l; i <= r; ++i) { dp[nd][i] = INF; } for (int i = l; i <= mid; ++i) { for (int j = mid + 1; j <= r; ++j) { dp[nd][i] = min(dp[nd][i], dp[nd * 2][i] + dp[nd * 2 + 1][j] + a[i][j]); } } for (int i = mid + 1; i <= r; ++i) { for (int j = l; j <= mid; ++j) { dp[nd][i] = min(dp[nd][i], dp[nd * 2][j] + dp[nd * 2 + 1][i] + a[i][j]); } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { cin >> a[i][j]; } } build(1, 1, n); long long ans = INF; for (int i = 1; i <= n; ++i) { ans = min(ans, dp[1][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...