제출 #487444

#제출 시각아이디문제언어결과실행 시간메모리
487444KienTranBest Place (NOI17_bestplace)C++14
100 / 100
36 ms3444 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int O = 1e5 + 5; const int inf = 1e18; int n, a[O], b[O], sumA[O], sumB[O]; int solban(){ int res = inf; for (int i = 1; i <= 100; ++ i){ for (int j = 1; j <= 100; ++ j){ int cost = 0; for (int z = 1; z <= n; ++ z){ cost += abs(a[z] - i) + abs(b[z] - j); } res = min(res, cost); } } return res; } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL)); cin >> n; for (int i = 1; i <= n; ++ i){ cin >> a[i] >> b[i]; } sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); for (int i = 1; i <= n; ++ i){ sumA[i] = sumA[i - 1] + a[i]; sumB[i] = sumB[i - 1] + b[i]; } int Max = inf, X = 0; for (int i = 1; i <= n; ++ i){ int cost = a[i] * i - sumA[i] + sumA[n] - sumA[i] - a[i] * (n - i); if (cost < Max){ Max = cost; X = a[i]; } } Max = inf; int Y = 0; for (int i = 1; i <= n; ++ i){ int cost = b[i] * i - sumB[i] + sumB[n] - sumB[i] - b[i] * (n - i); if (cost < Max){ Max = cost; Y = b[i]; } } int res = 0; for (int i = 1; i <= n; ++ i) res += abs(X - a[i]) + abs(Y - b[i]); cout << X << " " << Y; }

컴파일 시 표준 에러 (stderr) 메시지

bestplace.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
#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...