제출 #1318183

#제출 시각아이디문제언어결과실행 시간메모리
1318183JuanJLCoin Collecting (JOI19_ho_t4)C++20
8 / 100
173 ms428 KiB
#include <bits/stdc++.h> #define fst first #define snd second #define pb push_back #define SZ(x) (int)x.size() #define ALL(x) x.begin(),x.end() #define forn(i,a,b) for(int i = a; i<b; i++) #define mset(a,v) memset(a,v,sizeof(a)) #define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; typedef long long ll; int main(){ ll n; cin>>n; vector<pair<ll,ll>> p(2*n); forn(i,0,2*n) cin>>p[i].fst>>p[i].snd; sort(ALL(p)); ll res = 10000000000000000; //forn(i,0,SZ(p)) cout<<p[i].fst<<" "<<p[i].snd<<'\n'; forn(c,0,1<<(2*n)){ ll pres=0; ll cnt = 0; pair<ll,ll> p1 = {1,1}; pair<ll,ll> p2 = {1,2}; forn(i,0,2*n){ if(c&(1<<i)){ //cout<<1<<" ("<<p[i].fst<<" "<<p1.fst<<") ("<<p[i].snd<<" "<<p1.snd<<") "; cnt++; pres+=abs(p[i].fst-p1.fst)+abs(p[i].snd-p1.snd); p1.fst++; }else{ //cout<<0<<" ("<<p[i].fst<<" "<<p2.fst<<") ("<<p[i].snd<<" "<<p2.snd<<") ";; cnt--; pres+=abs(p[i].fst-p2.fst)+abs(p[i].snd-p2.snd); p2.fst++; } } if(cnt==0) res=min(res,pres); else pres=-1; //cout<<" --------- "<<pres<<'\n'; } cout<<res<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...