Submission #674590

#TimeUsernameProblemLanguageResultExecution timeMemory
674590HuyATCoin Collecting (JOI19_ho_t4)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define fp(file) freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); #define newl "\n" #define ms(a,v) memset(a,v,sizeof(a)) #define ar array #define sz(x) ((int)x.size()) #define r1(a) (a).begin(), (a).end() #define r2(a,start,end) a + start,a + end + 1 #define PI 3.1415926535897932384626433832795l #define ft first #define sd second typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int MaxN = 1e5; const int MaxV = 1e7; const ll mod = 1e9 + 7; const ll inf = 1e9; const ld eps = 1e-9; mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); #define SHUF(r) shuffle(r, RNG); struct Cord { int x,y; friend istream& operator >> (istream& in,Cord &inp) { in >> inp.x; in >> inp.y; return in; } friend bool operator < (const Cord &a,const Cord &b) { return (a.x < b.x || (a.x == b.x && a.y < b.y)); } }; Cord a[MaxN * 2 + 1]; int n; void rd() { cin >> n; n *= 2; for(int i = 1;i <= n;++i) cin >> a[i]; } void compress(ll &s) { s = 0; for(int i = 1;i <= n;++i) { if(a[i].y >= 2) s += a[i].y - 2LL,a[i].y = 2; else s += 1LL - a[i].y,a[i].y = 1; } } void cut(vector<int> &dis,ll &cnt_up,ll &cnt_down) { for(int i = 1;i <= n;++i) { if(a[i].y == 2) ++cnt_up; else ++cnt_down; dis.push_back(a[i].x); } } ll solve() { ll ans = 0,cnt_up = 0,cnt_down = 0; compress(ans); vector<int> dis; cut(dis,cnt_up,cnt_down); ans += abs(cnt_up - cnt_down) / 2; sort(dis.begin(),dis.end()); for(int i = 0;i < (int)dis.size();++i) ans += abs(dis[i] - (i + 2) / 2); return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int tc; // cin >> tc; // for(int i = 1;i <= tc;++i) // { // // } rd(); cout << solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...