Submission #209265

#TimeUsernameProblemLanguageResultExecution timeMemory
209265kostia244Coin Collecting (JOI19_ho_t4)C++17
0 / 100
7 ms2680 KiB
#pragma GCC optimize("O2") #pragma GCC target("avx,avx2,sse,sse2,ssse3,fma,tune=native") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define all(x) x.begin(), x.end() #define pb push_back using namespace std; using ll = long long; using vi = vector<ll>; using pi = pair<ll, ll>; const int maxn = 1e5 + 5; ll n, dp[maxn][3]; map<int, vi> t; vector<pi> a; ll dist(pi a, pi b) { return abs(a.first - b.first) + abs(a.second - b.second); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int x, y, i = 0; i < 2*n; i++) cin >> x >> y, t[x].pb(y); for(auto i : t) { int l = 0, r = i.second.size(), q = 0; sort(all(i.second)); while(l<r) { if(q) a.pb({i.first, i.second[l++]}); else a.pb({i.first, i.second[--r]}); q ^= 1; } } memset(dp, 0x3f, sizeof dp); dp[0][0] = 0; for(int i = 0; i < 2*n; i++) { dp[1 + (i/2)][0] = min(dp[1 + (i/2)][0], dp[i/2][2] + dist(a[i], {1 + (i/2), 1})); dp[1 + (i/2)][0] = min(dp[1 + (i/2)][0], dp[i/2][1] + dist(a[i], {1 + (i/2), 2})); dp[i/2][1] = min(dp[i/2][1], dp[i/2][0] + dist(a[i], {1 + (i/2), 1})); dp[i/2][2] = min(dp[i/2][2], dp[i/2][0] + dist(a[i], {1 + (i/2), 2})); } cout << dp[n][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...