답안 #567916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567916 2022-05-24T11:01:16 Z Arvin Road Construction (JOI21_road_construction) C++11
11 / 100
10000 ms 29100 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll maxA = 1e10;

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	int n, k;
	cin >> n >> k;
	
	pair<ll, ll> p[n];
	for(int x=0;x<n;x++){
		cin >> p[x].first >> p[x].second;
		p[x] = {p[x].first+p[x].second+maxA, p[x].first-p[x].second+maxA};
	}
	
	vector<pair<ll, ll>> vX, vY;
	priority_queue<array<ll, 4>, vector<array<ll, 4>>, greater<array<ll, 4>>> pq;
	for(int x=0;x<n;x++){
		vX.push_back({p[x].first, x});
		vY.push_back({p[x].second, x});
	}
	
	sort(vX.begin(), vX.end());
	sort(vY.begin(), vY.end());
	
	for(int x=0;x+1<n;x++){
		pq.push({vX[x+1].first-vX[x].first, 0, x, x+1});
		pq.push({vY[x+1].first-vY[x].first, 1, x, x+1});
	}
	
	while(k > 0 && !pq.empty()){
		ll val = pq.top()[0], type = pq.top()[1], l = pq.top()[2], r = pq.top()[3];
		pq.pop();
		
		if(type == 0){
			int idx1 = vX[l].second, idx2 = vX[r].second;
			if(max(abs(p[idx2].first-p[idx1].first), abs(p[idx2].second-p[idx1].second)) == val){
				cout << val << "\n";
				k--;
			}
			if(r+1 < n){
				pq.push({p[vX[r+1].second].first-p[vX[l].second].first, 0, l, r+1});
			}
		} else {
			int idx1 = vY[l].second, idx2 = vY[r].second;
			if(abs(p[idx2].first-p[idx1].first) < abs(p[idx2].second-p[idx1].second) && abs(p[idx2].second-p[idx1].second) == val){
				cout << val << "\n";
				k--;
			}
			if(r+1 < n){
				pq.push({p[vY[r+1].second].second-p[vY[l].second].second, 1, l, r+1});
			}
		}
	}
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 3052 KB Output is correct
2 Correct 116 ms 2956 KB Output is correct
3 Correct 87 ms 3020 KB Output is correct
4 Correct 86 ms 3128 KB Output is correct
5 Correct 95 ms 1852 KB Output is correct
6 Correct 7 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 406 ms 29084 KB Output is correct
2 Correct 385 ms 29100 KB Output is correct
3 Correct 84 ms 2900 KB Output is correct
4 Correct 233 ms 28916 KB Output is correct
5 Correct 261 ms 29092 KB Output is correct
6 Correct 235 ms 29052 KB Output is correct
7 Correct 258 ms 28604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 28580 KB Output is correct
2 Correct 406 ms 28580 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 116 ms 28564 KB Output is correct
5 Execution timed out 10050 ms 28616 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 28580 KB Output is correct
2 Correct 406 ms 28580 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 116 ms 28564 KB Output is correct
5 Execution timed out 10050 ms 28616 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 3052 KB Output is correct
2 Correct 116 ms 2956 KB Output is correct
3 Correct 87 ms 3020 KB Output is correct
4 Correct 86 ms 3128 KB Output is correct
5 Correct 95 ms 1852 KB Output is correct
6 Correct 7 ms 468 KB Output is correct
7 Execution timed out 10080 ms 13284 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 119 ms 3052 KB Output is correct
2 Correct 116 ms 2956 KB Output is correct
3 Correct 87 ms 3020 KB Output is correct
4 Correct 86 ms 3128 KB Output is correct
5 Correct 95 ms 1852 KB Output is correct
6 Correct 7 ms 468 KB Output is correct
7 Correct 406 ms 29084 KB Output is correct
8 Correct 385 ms 29100 KB Output is correct
9 Correct 84 ms 2900 KB Output is correct
10 Correct 233 ms 28916 KB Output is correct
11 Correct 261 ms 29092 KB Output is correct
12 Correct 235 ms 29052 KB Output is correct
13 Correct 258 ms 28604 KB Output is correct
14 Correct 310 ms 28580 KB Output is correct
15 Correct 406 ms 28580 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 116 ms 28564 KB Output is correct
18 Execution timed out 10050 ms 28616 KB Time limit exceeded
19 Halted 0 ms 0 KB -