Submission #721019

#TimeUsernameProblemLanguageResultExecution timeMemory
721019minhcoolWiring (IOI17_wiring)C++17
0 / 100
1 ms436 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 2e3 + 5; const int oo = 1e9 + 7, mod = 1e9 + 7; /* New algo: */ int n, m; int r[N], b[N]; int dp[N][N]; int pref[N][N], mini[N]; ll min_total_length(vector<int> R, vector<int> B){ n = R.size(), m = B.size(); for(int i = 0; i < n; i++) r[i + 1] = R[i]; for(int i = 0; i < m; i++) b[i + 1] = B[i]; for(int i = 0; i <= n; i++){ for(int j = 0; j <= m; j++) dp[i][j] = oo; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) pref[i][j] = pref[i][j - 1] + abs(r[i] - b[j]); mini[i] = oo; for(int j = 1; j <= m; j++) mini[i] = min(mini[i], abs(r[i] - b[j])); } //cout << pref[1][1] << "\n"; dp[0][0] = 0; for(int i = 0; i <= n; i++){ for(int j = 0; j <= m; j++){ for(int nxt = j + 1; nxt <= m; nxt++){ dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j] + pref[i + 1][nxt] - pref[i + 1][j]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + mini[i + 1]); cout << i << " " << j << " " << dp[i][j] << "\n"; } } return dp[n][m]; } /* void process(){ int n, m; cin >> n >> m; vector<int> v1, v2; for(int i = 0; i < n; i++){ int x; cin >> x; v1.pb(x); } for(int i = 0; i < m; i++){ int x; cin >> x; v2.pb(x); } cout << min_total_length(v1, v2); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); process(); } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...