답안 #486922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486922 2021-11-13T11:43:02 Z jamezzz Road Construction (JOI21_road_construction) C++17
0 / 100
359 ms 8480 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 2023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define maxn 250005

int n,k,x,y;
vi ans;
vii v;
set<ii> s;

int num(int d){
	s.clear();
	ans.clear();
	int l=0;
	for(int i=0;i<n;++i){
		while(v[l].fi+d<v[i].fi)s.erase({v[l].se,l++});
		auto it=s.lower_bound({v[i].se-d,-INF});
		while(it!=s.end()){
			if(v[i].se+d>=it->fi){
				ans.pb(max(abs(v[i].fi-v[it->se].fi),abs(v[i].se-v[it->se].se)));
				++it;
			}
			else break;
			if(sz(ans)==k)break;
		}
		if(sz(ans)==k)break;
		s.insert({v[i].se,i});
	}
	return sz(ans);
}

int main(){
	sf("%d%d",&n,&k);
	for(int i=0;i<n;++i){
		sf("%d%d",&x,&y);
		v.pb(x+y,x-y);
	}
	sort(all(v));
	int lo=1,hi=2000000000,mid,res;
	while(lo<=hi){
		mid=lo+(hi-lo)/2;
		if(num(mid)>=k)res=mid,hi=mid-1;
		else lo=mid+1;
	}
	num(res-1);
	sort(all(ans));
	while(sz(ans)!=k)ans.pb(res);
	for(int i:ans)pf("%d\n",i);
}

Compilation message

road_construction.cpp: In function 'int num(int)':
road_construction.cpp:43:45: warning: operation on 'l' may be undefined [-Wsequence-point]
   43 |   while(v[l].fi+d<v[i].fi)s.erase({v[l].se,l++});
      |                                            ~^~
road_construction.cpp: In function 'int main()':
road_construction.cpp:60:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  sf("%d%d",&n,&k);
      |    ^
road_construction.cpp:62:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |   sf("%d%d",&x,&y);
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 8456 KB Output is correct
2 Correct 357 ms 8480 KB Output is correct
3 Runtime error 14 ms 2236 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 228 ms 7436 KB Output is correct
2 Correct 359 ms 7420 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 228 ms 7436 KB Output is correct
2 Correct 359 ms 7420 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -