Submission #1051336

#TimeUsernameProblemLanguageResultExecution timeMemory
1051336pawned전선 연결 (IOI17_wiring)C++17
0 / 100
1094 ms10396 KiB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; #include "wiring.h" ll min_total_length(vector<int> r_g, vector<int> b_g) { vi r, b; for (int x : r_g) r.pb(x); for (int x : b_g) b.pb(x); int N = r.size(); int M = b.size(); map<int, ll> dp; // dp[i][j]: min cost to connect first i red (exclusive) // with first j blue (exclusive) dp[0] = 0; for (int i = 1; i <= N; i++) { // cout<<"at "<<i<<endl; map<int, ll> newdp; // consider only up to previous blue minus 10, next blue plus 10 auto it = lower_bound(b.begin(), b.end(), i); ll lb = 1; if (it != b.begin()) { auto it2 = it; it2--; lb = max(lb, *it2 - 10); } auto it3 = lower_bound(b.begin(), b.end(), i); ll rb = M; if (it3 != b.end()) { rb = min(rb, *it3 + 10); } for (int j = lb; j <= rb; j++) { // only consider up to consec // cout<<"j: "<<j<<endl; newdp[j] = 1e18; if (newdp.find(j - 1) != newdp.end()) newdp[j] = min(newdp[j], newdp[j - 1] + abs(r[i - 1] - b[j - 1])); if (dp.find(j) != dp.end()) newdp[j] = min(newdp[j], dp[j] + abs(r[i - 1] - b[j - 1])); if (dp.find(j - 1) != dp.end()) newdp[j] = min(newdp[j], dp[j - 1] + abs(r[i - 1] - b[j - 1])); } dp = newdp; /* cout<<"dp: "<<endl; for (pair<int, ll> p : dp) cout<<p.fi<<": "<<p.se<<endl;*/ } return dp[M]; }
#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...