제출 #588072

#제출 시각아이디문제언어결과실행 시간메모리
588072angelo_torresBest Place (NOI17_bestplace)C++17
100 / 100
48 ms5564 KiB
#include <bits/stdc++.h> #define f(i,j,n) for(ll i = j; i < n; ++i) #define fr(i,j,n) for(ll i = j; i >= n; --i) #define ff first #define ss second #define sz(v) (int) v.size() using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> ii; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<int> vi; typedef long double ld; const int N = 1e5 + 20; const int M = 2e3 + 20; const ll inf = 1e18; ll n,x[N],y[N],pr[N],su[N]; ll axe(vll v){ sort(v.begin(),v.end()); f(i,0,n) pr[i] = su[i]; ll ct = 1; pr[0] = 0; f(i,1,n){ pr[i] = pr[i-1] + abs(v[i]-v[i-1])*ct, ct++; // cout << pr[i] << endl; } su[n-1] = 0, ct = 1; fr(i,n-2,0){ su[i] = su[i+1] + abs(v[i+1]-v[i])*ct, ct++; // cout << su[i] << endl; } ll mn = inf,id = 0; f(i,0,n){ // cout << pr[i] << " " << su[i] << endl; if(pr[i]+su[i] < mn) mn = pr[i] + su[i], id = i; } return v[id]; } void solve(){ cin >> n; f(i,1,n+1) cin >> x[i] >> y[i]; vll v = {}; pll ans = {0,0}; f(i,1,n+1) v.push_back(x[i]); ans.ff = axe(v); v.clear(); f(i,1,n+1) v.push_back(y[i]); ans.ss = axe(v); cout << ans.ff << " " << ans.ss << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; while(tc--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...