제출 #589806

#제출 시각아이디문제언어결과실행 시간메모리
589806myrcellaCoin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms212 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 a[2][maxn],b[maxn]; int bg[2]={0,0},ed[2]={0,0}; int n; int main() { cin.tie(0); cin>>n; ll ans = 0; rep(i,0,2*n) { int x,y; cin>>x>>y; ans += abs(y-1); if (y<=1) a[0][ed[0]++] = x; else a[1][ed[1]++]=x; } sort(a[0],a[0]+ed[0]); sort(a[1],a[1]+ed[1]); int curx =0; // debug(ans); while (bg[0]<ed[0] or bg[1]<ed[1]) { curx++; int cur = 0; if (bg[0]==ed[0] or (bg[1]<ed[1] and a[1][bg[1]] < a[0][bg[0]])) cur = 1; if (bg[cur]+1==ed[cur] or (bg[1-cur]!=ed[1-cur] and a[1-cur][bg[1-cur]]-a[cur][bg[cur]+1]<=0)) { ans--; ans += abs(a[1-cur][bg[1-cur]]-curx); // debug(a[1-cur][bg[1-cur]]); bg[1-cur]++; // debug(233); } else { if (cur==0) ans++; else ans--; ans += abs(a[cur][bg[cur]]-curx); // debug(a[cur][bg[cur]]); bg[cur]++; } ans += abs(a[cur][bg[cur]]-curx); // debug(a[cur][bg[cur]]); bg[cur]++; // debug(ans); // debug(curx); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...