이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
inline char readchar() {
const int S = 1<<20; // buffer size
static char buf[S], *p = buf, *q = buf;
if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
return *p++;
}
inline int nextint() {
int x = 0, c = readchar(), neg = false;
while(('0' > c || c > '9') && c!='-' && c!=EOF) c = readchar();
if(c == '-') neg = true, c = readchar();
while('0' <= c && c <= '9') x = x*10 + (c^'0'), c = readchar();
if(neg) x = -x;
return x; // returns 0 if EOF
}
const int inf=2e9+5;
int n,k;
vector<pair<int,int>> vec;
vector<ll> ans;
bool check(ll d){
int l=0;
set<pair<int,int>> S;
ans.clear();
for(int r=0;r<n;r++){
while(vec[l].f<max(-(ll)inf,(ll)vec[r].f-d)){
S.erase({vec[l].s,l});
l++;
}
auto it2=S.upper_bound({min((ll)inf,(ll)vec[r].s+d),inf});
for(auto it=S.lower_bound({max(-(ll)inf,(ll)vec[r].s-d),-inf});it!=it2;it++){
int x=(*it).s;
ans.push_back(max(abs((ll)vec[x].f-(ll)vec[r].f),abs((ll)vec[x].s-(ll)vec[r].s)));
if((int)ans.size()>=k) return true;
}
S.insert({vec[r].s,r});
}
return false;
}
int main() {_
n=nextint();
k=nextint();
for(int i=0;i<n;i++){
int x,y;
x=nextint();
y=nextint();
int xx=y+x;
int yy=y-x;
vec.push_back({xx,yy});
}
sort(all(vec));
ll l=0,r=(ll)4e9;
while(l<r){
ll mid=(l+r)/2;
if(check(mid)){
r=mid;
}
else{
l=mid+1;
}
}
check(l-1);
sort(all(ans));
while((int)ans.size()<k) ans.push_back(l);
for(auto v:ans){
cout<<v<<'\n';
}
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
컴파일 시 표준 에러 (stderr) 메시지
road_construction.cpp: In function 'void setIO(std::string)':
road_construction.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |