Submission #417998

#TimeUsernameProblemLanguageResultExecution timeMemory
417998SlavicGWiring (IOI17_wiring)C++17
0 / 100
1 ms204 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define forn(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define sz(a) (int)a.size() #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define GR(a,n,m) vector<vector<int>> a(n, vector<int>(m, 0)); ll min_total_length(vector<int> a, vector<int> b) { if(sz(a) > sz(b))swap(a,b); int n = sz(a), m = sz(b); ll ret = LLONG_MAX; if(max(n, m) <= 5000) { for(int start_poz = 0;start_poz + n - 1 < m;start_poz++){ int idx = start_poz; ll ans = 0; for(int i = start_poz;i < n;i++){ ans += abs(a[i] - b[i]); idx++; } for(int i = 0;i < start_poz;i++){ int poz = lower_bound(all(a), b[i]) - a.begin(); ll mn = LLONG_MAX; for(int j = max(poz - 5, 0);j < min(poz + 5, m);j++){ mn = min(mn, 1LL * abs(b[i] - a[j])); } ans += mn; } for(int i = idx;i < m;i++){ int poz = lower_bound(all(a), b[i]) - a.begin(); ll mn = LLONG_MAX; for(int j = max(poz - 5, 0);j < min(poz + 5, m);j++){ mn = min(mn, 1LL * abs(b[i] - a[j])); } ans += mn; } ret = min(ret, ans); } return ret; } int idx = 0; ll ans = 0; for(int i = 0;i < n;i++){ ans += abs(a[i] - b[i]); idx++; } for(int i = idx;i < m;i++){ int poz = lower_bound(all(a), b[i]) - a.begin(); ll mn = LLONG_MAX; for(int j = max(poz - 5, 0);j < min(poz + 5, m);j++){ mn = min(mn, 1LL * abs(b[i] - a[j])); } ans += mn; } return ans; }
#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...