Submission #496956

#TimeUsernameProblemLanguageResultExecution timeMemory
496956Nuraly_SerikbayCoin Collecting (JOI19_ho_t4)C++14
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> #define endl "\n" #define mp make_pair #define pb push_back #define F first #define S second #define sz size() #define rep(i,k,n) for(int i = k ; i <= n ; ++i) #define per(i,k,n) for(int i = k ; i >= n ; --i) #define Zymraq() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define all(x) x.begin(),x.end() #define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout) #define toqta return 0 #define PERMUTE next_permutation #define no cout<<"No"<<endl; #define yes cout<<"Yes"<<endl; #define a() a + 1, a + n + 1 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef string S; typedef double ld; typedef long double lld; const int N = 1e6 + 17; const int modd = 1e9 + 7; const ll INF = 1e18 - 19; const int P = 37; const ll NN = 1e7 + 17; const ld eps = 1e-19; const double pi = 3.141592653589793238462643383279 ; bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){ return (a.second < b.second); } void pre (ll a) { cout << fixed << setprecision(a); return; } ll n; ll x[N], y[N]; ll pos[1000][1000]; ll totalans = 0; inline void Solution () { cin >> n; for (int i = 1; i <= n * 2; ++ i) { cin >> x[i] >> y[i]; if (x[i] <= n && x[i] > 0 && y[i] <= 2 && y[i] > 0) pos[x[i]][y[i]] ++; } for (int i = 1; i <= n * 2; ++ i) { if (x[i] > 0 && y[i] > 0 && x[i] <= n && y[i] <= 2 && pos[x[i]][y[i]] != 0) continue; ll mn = INF, new_posx, new_posy; for (int j = 1; j <= n; ++ j) { if (!pos[j][1] && mn > abs (x[i] - j) + abs(y[i] - 1)) { new_posx = j, new_posy = 1; mn = abs (x[i] - j) + abs (y[i] - 1); } if (!pos[j][2] && mn > abs (x[i] - j) + abs (y[i] - 2)) { new_posx = j, new_posy = 2; mn = abs (x[i] - j) + abs (y[i] - 2); } } if (mn != INF) { totalans += mn; pos[new_posx][new_posy] = 1; } } for (int i = 1; i <= n * 2; ++ i) { if (x[i] > 0 && y[i] > 0 && x[i] <= n && y[i] <= 2 && pos[x[i]][y[i]] > 1) { ll mn = INF, new_posx, new_posy; for (int j = 1; j <= n; ++ j) { if (!pos[j][1] && mn > abs (x[i] - j) + abs (y[i] - 1)) { new_posx = j, new_posy = 1; mn = abs (x[i] - j) + abs (y[i] - 1); } if (!pos[j][2] && mn > abs (x[i] - j) + abs (y[i] - 2)) { new_posx = j, new_posy = 2; mn = abs (x[i] - j) + abs(y[i] - 2); } } // cout << mn << ' ' << new_posx << ' ' << new_posy << '\n' << x[i] << y[i]; if (mn != INF) { pos[x[i]][y[i]] --; totalans += mn; pos[new_posx][new_posy] = 1; } } } cout << totalans; return; } int main () { Zymraq(); Solution (); exit (0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...