Submission #884371

#TimeUsernameProblemLanguageResultExecution timeMemory
884371RaresFelixCoin Collecting (JOI19_ho_t4)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("O3") //#pragma GCC target("avx,avx2,fma") #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using db = long double; // or double, if TL is tight using str = string; using ii = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; ll solve(vll &V, ll st, ll dr, ll delta) { ll re = 0; for(auto &it : V) { if(it < st) { re += st - it; it = st; } if(it > dr) { re += it - dr; it = dr; } } sort(all(V)); ll p = 0; for(ll i = st; i < dr; ++i) { ///bara dintre i si i + 1 while(p < sz(V) && V[p] <= i) ++p; re += abs(p - 1ll * delta * (i - st + 1)); } return re; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); ll n; vll X, Y; cin >> n; for(ll i = 0; i < 2 * n; ++i) { ll x, y; cin >> x >> y; X.push_back(x); Y.push_back(y); } ll re = solve(X, 1, n, 2) + solve(Y, 1, 2, n); cout << re << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...