Submission #292148

#TimeUsernameProblemLanguageResultExecution timeMemory
292148YJUCoin Collecting (JOI19_ho_t4)C++14
100 / 100
67 ms5928 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=2e5+5; const ld pi=3.14159265359; const ll INF=(1LL<<60); typedef pair<ll,pair<ll,pair<ll,pll> > > TY; #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,x,y,cnt[N][3],lst=1,ans; pll to(pll A){ if(A.X<1)ans+=abs(A.X-1),A.X=1; if(A.X>n)ans+=abs(A.X-n),A.X=n; if(A.Y>2)ans+=abs(A.Y-2),A.Y=2; if(A.Y<1)ans+=abs(A.Y-1),A.Y=1; return A; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; REP1(i,2*n){ cin>>x>>y; pll nd=to(mp(x,y)); ++cnt[nd.X][nd.Y]; } ll t1=0,t2=0; REP1(i,n){ t1+=cnt[i][1]-1; t2+=cnt[i][2]-1; if(t1*t2<0){ ll tmp=min(abs(t1),abs(t2)); ans+=tmp; if(t1<0){ t1+=tmp;t2-=tmp; }else{ t1-=tmp;t2+=tmp; } } ans+=abs(t1)+abs(t2); } cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...