Submission #1089071

#TimeUsernameProblemLanguageResultExecution timeMemory
1089071efishelCoin Collecting (JOI19_ho_t4)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector <ll>; using ii = pair <ll, ll>; using vii = vector <ii>; int main () { cin.tie(nullptr) -> sync_with_stdio(false); ll n; cin >> n; vii ve(2*n); for (auto &[x, y] : ve) cin >> x >> y; ll ans = 0; auto fclamp = [&](ll l, ll r, ll &val) { if (val < l) { ans += l-val; val = l; } if (val > r) { ans += val-r; val = r; } }; for (auto &[x, y] : ve) { fclamp(1, n, x); fclamp(1, 2, y); } vll asg(2*n); iota(asg.begin(), asg.end(), 0); auto cost = [&](ll pos, ll i) { auto [x, y] = ve[i]; return abs(x-(1+pos%n)) + abs(y-(1+pos/n)); }; auto shsw = [&](ll i, ll j) { return cost(i, asg[j]) + cost(j, asg[i]) < cost(i, asg[i]) + cost(j, asg[j]); }; for (ll k = 0; k < 2*n; k++) { for (ll i = 0; i < 2*n; i++) { for (ll j = 0; j < 2*n; j++) { if (shsw(i, j)) swap(asg[i], asg[j]); } } } for (ll i = 0; i < 2*n; i++) ans += cost(i, asg[i]); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...