Submission #1310135

#TimeUsernameProblemLanguageResultExecution timeMemory
1310135tntCoin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms576 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back                    
#define ll long long  
#define f first
#define s second
//#define sz(v) int(v.size())
#define all(v) v.begin(),v.end()

int mod =  1e9 + 7;
const int N = 2000 + 10,k = 317 + 1;
const ll inf = 1e18 + 100;
ll func(int x,int y,int x1,int y1){
    return abs(x - x1) + abs(y - y1);
}
bool was[N],was1[N];
int x[N],y[N];
void solve(){
    int n;
    cin >> n;
    for(int i = 1; i <= 2 * n; i++){
        cin >> x[i] >> y[i];
    }
    ll ans = 0,cnt = 2 * n;
    while(cnt--){
        ll mn = inf;
        pair <int,int> pr;
        for(int i = 1; i <= 2 * n; i++){
            if(was[i] == 1) continue;
            int x1 = i,y1 = i / (n + 1) + 1;
            if(x1 > n) x1 -= n;
            for(int j = 1; j <= n * 2; j++){
                if(was1[j] == 1) continue;
                if(mn >= func(x[j],y[j],x1,y1)){
                    mn = func(x[j],y[j],x1,y1);
                    pr = {i,j};
                }
            }
        }
        was[pr.f] = was1[pr.s] = 1;
        int x1 = pr.f;
        if(x1 > n) x1 -= n;
        ans += func(x[pr.s],y[pr.s],x1, pr.f / (n + 1) + 1);
    }
    cout << ans;
        
    
}
signed main(){
    //freopen("time.in", "r", stdin);
    //freopen("time.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t1 = 1;
    while(t1--){
        solve();
    }
}                          	
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...