Submission #639289

#TimeUsernameProblemLanguageResultExecution timeMemory
639289tabr전선 연결 (IOI17_wiring)C++17
17 / 100
1084 ms6596 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif long long min_total_length(vector<int> a, vector<int> b) { int n = (int) a.size(); int m = (int) b.size(); a.insert(a.end(), b.begin(), b.end()); vector<int> order(n + m); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { return a[i] < a[j]; }); const long long inf = (long long) 1e18; vector<long long> dp(n + m + 1, inf); dp[0] = 0; for (int i = 0; i < n + m; i++) { int flag = 0; long long cnt = 1; long long sum = min(dp[i], dp[i + 1]) - a[order[i]]; long long left = a[order[i]]; long long right = 0; for (int j = i + 1; j < n + m; j++) { if ((order[i] < n) == (order[j] < n)) { if (flag) { break; } cnt++; sum -= a[order[j]]; left = a[order[j]]; } else { if (!flag) { right = a[order[j]]; } flag = 1; cnt--; sum += a[order[j]]; dp[j + 1] = min(dp[j + 1], sum + max(0LL, cnt) * right + min(0LL, cnt) * left); } } } debug(dp); return dp[n + m]; } #ifdef tabr int main() { ios::sync_with_stdio(false); cin.tie(0); debug(min_total_length({1, 2, 3, 7}, {0, 4, 5, 9, 10})); return 0; } #endif
#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...