# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
893356 | vjudge1 | Road Construction (JOI21_road_construction) | C++17 | 543 ms | 48068 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag=false;
if(x>y) x=y;flag|=true;
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag=false;
if (x<y) x=y;flag|=true;
return flag;
}
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e9+7;
const ll mod=1e9+7;
const ll N=3e3+5;
const ld eps=1e-9;
vll x,y;
ll dis(ll i,ll j){
return abs(x[i]-x[j])+abs(y[i]-y[j]);
}
void solve(){
ll i,j;
ll n,k;
cin>>n>>k;
x.resize(n);
y.resize(n);
bool flag=true;
for(i=0;i<n;i++) {
cin>>x[i]>>y[i];
if(y[i])flag=false;
}
if(n<=1000){
vll v;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
v.pb(dis(i,j));
}
}
sort(all(v));
for(i=0;i<k;i++) cout<<v[i]<<endl;
return;
}
if(flag){
vector<pair<ll,ll>> v;
for(i=0;i<n;i++){
v.pb({x[i],y[i]});
}
sort(all(v));
map<pair<ll,ll>,ll> mp;
set<pair<ll,pair<ll,ll>>> seg;
for(i=1;i<n;i++){
seg.ins({dis(i,i-1),{i-1,i}});
}
for(i=0;i<k;i++){
ll x=(seg.begin()->sc).fr,y=(seg.begin()->sc).sc;
cout<<dis(x,y)<<endl;
seg.erase(seg.begin());
if(x>0 && mp[{x-1,y}]==0){
mp[{x-1,y}]++;
seg.ins({dis(x-1,y),{x-1,y}});
}
if(y<n-1 && mp[{x,y+1}]){
mp[{x,y+1}]++;
seg.ins({dis(x,y+1),{x,y+1}});
}
}
}
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |