제출 #705743

#제출 시각아이디문제언어결과실행 시간메모리
705743myrcellaCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms316 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define pii pair<int,int> #define ll long long #define pll pair<ll,ll> #define rep(i,a,b) for (int i=(a);i<(b);i++) #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define pq priority_queue #define debug(x) cerr<<#x<<"="<<x<<"\n" const int maxn = 2e5+10; int n; int ans[maxn]; set <int> a,b; int main() { cin.tie(0); cin>>n; rep(i,1,n+1) a.insert(i),b.insert(i); ll ans = 0; rep(i,0,2*n) { int x,y; cin>>x>>y; int dif1 = 2e9+10,val1; int dif2 = 2e9+10,val2; set<int>::iterator it = lower_bound(ALL(a),x); if (it!=a.end() and ((*it)-x)<dif1) val1 = *it, dif1 = val1-x; if (it!=a.begin() and (x-(*(--it)))<dif1) val1 = *it, dif1 = x - val1; it = lower_bound(ALL(b),x); if (it!=b.end() and ((*it)-x)<dif2) val2 = *it, dif2 = val2-x; if (it!=b.begin() and (x-(*(--it)))<dif2) val2 = *it, dif2 = x - val2; if (dif1+abs(y-1)<dif2+abs(y-2)) { a.erase(val1); ans += dif1+abs(y-1); debug(val1),debug(1); } else { b.erase(val2); ans += dif2+abs(y-2); debug(val2),debug(2); } debug(ans); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...