Submission #949212

# Submission time Handle Problem Language Result Execution time Memory
949212 2024-03-19T03:47:49 Z vjudge1 Best Place (NOI17_bestplace) C++17
0 / 100
1000 ms 1884 KB
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   *  |    |  |  | /   /| |\  | /   |  |  * | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
// 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 fy = [&](int m, int u){
		int res = 0;
		for(int i = 0; i < n; i++){res += abs(b[i]-m) + abs(a[i]-u);}
		return res;
	};
	auto fx = [&](int m){
		int l = 0, r = 1e9, cnt = 100;
		while(l <= r && cnt--){
			int m1 = l+(r-l)/3;
			int m2 = r-(r-l)/3;
			if(fy(m1, m) < fy(m2, m))r = m2;
			else{
				l = m1;
				y = m1;
			}
		}
		return fy(l, m);
	};
	int l = 0, r = 1e9, cnt = 100;
	while(l <= r && cnt--){
		int m1 = l+(r-l)/3;
		int m2 = r-(r-l)/3;
		if(fx(m1) < fx(m2))r = m2;
		else{
			l = m1;
			x = 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();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

bestplace.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 448 KB Output is correct
2 Incorrect 54 ms 440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 348 KB Output is correct
2 Incorrect 48 ms 600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 1884 KB Time limit exceeded
2 Halted 0 ms 0 KB -