이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | * | | | | / /| |\ | / | | * | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///*
// autor :: Rick Prime
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define int long long
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define order_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 1e7, inf = 1e9, mod = 1e9+7;
void solve(){
int n;
cin >> n;
int x = 0, y = 0;
int a[n], b[n];
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
}
auto fx = [&](int m){
int res = 0;
for(int i = 0; i < n; i++)res += abs(a[i]-m);
return res;
};
auto fy = [&](int m){
int res = 0;
for(int i = 0; i < n; i++)res += abs(b[i]-m);
return res;
};
int l = 0, r = 1e9;
while(l <= r){
int m1 = l+(r-l)/3;
int m2 = r-(r-l)/3;
if(fx(m1) < fx(m2))r = m2-1;
else{
l = m1+1;
x = m1;
}
}
l = 0; r = 1e9;
while(l <= r){
int m1 = l+(r-l)/3;
int m2 = r-(r-l)/3;
if(fy(m1) < fy(m2))r = m2-1;
else{
l = m1+1;
y = m1;
}
}
cout << x << ' ' << y << '\n';
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//cin >> test;
while(test--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bestplace.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |