Submission #893584

# Submission time Handle Problem Language Result Execution time Memory
893584 2023-12-27T07:14:58 Z vjudge1 Road Construction (JOI21_road_construction) C++14
5 / 100
10000 ms 22868 KB
#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 rall(x) x.rbegin(),x.rend()
#define int long long
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   @  |    |  |  | /   /| |\  | /   |  |  @ | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///*  
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
multiset<int> ans;
const int N = 3e5;
struct pt {
	int x, y, id;
};
pt a[N];
int n, k;
bool cmp_x (const pt & a, const pt & b) {
	return a.x < b.x || (a.x == b.x && a.y < b.y);
}
 
bool cmp_y (const pt & a, const pt & b) {
	return a.y < b.y;
}
double mindist;
int ansa, ansb;
 
void upd_ans (const pt & a, const pt & b) {
	double dist = abs(a.x-b.x) + abs(a.y-b.y);
	ans.insert(dist);
	if((int)ans.size()>k)ans.erase(ans.find(*--ans.end()));
	if (dist < mindist)
		mindist = dist,  ansa = a.id,  ansb = b.id;
}
void rec (int l, int r) {
	if (r - l <= 3) {
		for (int i=l; i<=r; ++i)
			for (int j=i+1; j<=r; ++j)
				upd_ans (a[i], a[j]);
		sort (a+l, a+r+1, &cmp_y);
		return;
	}
 
	int m = (l + r) >> 1;
	rec (l, m),  rec (m+1, r);
	static pt t[N];
	merge (a+l, a+m+1, a+m+1, a+r+1, t, &cmp_y);
	copy (t, t+r-l+1, a+l);
 
	int tsz = 0;
	for (int i=l; i<=r; ++i){
		for (int j=tsz-1; j>=0 && a[i].y - t[j].y < mindist; --j)
			upd_ans (a[i], t[j]);
		t[tsz++] = a[i];
	}
}
void solve(){
	cin >> n >> k;
	if(n*n < 1e8){
		vii v(n);
		vi ans2;
		for(auto &[i,j]:v)cin >> i >> j;
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				ans2.pb(abs(v[i].ff-v[j].ff)+abs(v[i].ss-v[j].ss));
			}
		}sort(all(ans2));
		for(int i = 0; i < k; i++)cout << ans2[i] << '\n';
		return;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].x >> a[i].y;
		a[i].id = i;
	}
	sort (a, a+n, &cmp_x);
	mindist = 1E20;
	rec (0, n-1);
	for(auto i:ans){
		cout << i << '\n';
	}
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int test = 1;
	//~ cin >> test;
	while(test--){
		solve();
	}
}

Compilation message

road_construction.cpp: In function 'void solve()':
road_construction.cpp:68:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   68 |   for(auto &[i,j]:v)cin >> i >> j;
      |             ^
road_construction.cpp: At global scope:
road_construction.cpp:89:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   89 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 53 ms 9140 KB Output is correct
2 Correct 53 ms 9148 KB Output is correct
3 Correct 33 ms 7100 KB Output is correct
4 Correct 38 ms 7220 KB Output is correct
5 Correct 50 ms 7864 KB Output is correct
6 Correct 18 ms 7464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 10058 ms 20328 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 133 ms 13168 KB Output is correct
2 Correct 163 ms 13176 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Execution timed out 10067 ms 8832 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 133 ms 13168 KB Output is correct
2 Correct 163 ms 13176 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Execution timed out 10067 ms 8832 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 9140 KB Output is correct
2 Correct 53 ms 9148 KB Output is correct
3 Correct 33 ms 7100 KB Output is correct
4 Correct 38 ms 7220 KB Output is correct
5 Correct 50 ms 7864 KB Output is correct
6 Correct 18 ms 7464 KB Output is correct
7 Incorrect 190 ms 22868 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 9140 KB Output is correct
2 Correct 53 ms 9148 KB Output is correct
3 Correct 33 ms 7100 KB Output is correct
4 Correct 38 ms 7220 KB Output is correct
5 Correct 50 ms 7864 KB Output is correct
6 Correct 18 ms 7464 KB Output is correct
7 Execution timed out 10058 ms 20328 KB Time limit exceeded
8 Halted 0 ms 0 KB -