답안 #1083436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083436 2024-09-03T06:24:47 Z _rain_ Road Construction (JOI21_road_construction) C++14
7 / 100
437 ms 36636 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fixbug false
#define int long long
 
void SETIO(string name = ""){
    if (name=="") return;
    freopen((name+".inp").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
    return;
}
 
#define ii pair<int,int>
#define x first
#define y second
 
const int maxn = 250000;
const int maxedge = 250000;
ii p[maxedge+2];
int n , k;
struct Node{
    int d;
    int x , y;
    bool operator < (const Node& other) const{
        if (d != other.d) return d < other.d;
        if (x != other.x) return x < other.x;
        return y < other.y;
    }
};
vector<Node> edg;
int d(ii x , ii y){
    return x.first - y.first + x.second - y.second;
}
 
void MST(){
    vector<int> ids(n);
    iota(ids.begin(),ids.end(),1);
    for (int turn = 1; turn <= 4; ++turn){
        sort(ids.begin(),ids.end(),[=](int i , int j){
                return p[i].x+p[i].y < p[j].x+p[j].y;
            });
        map<int,int,greater<int>> active_set;
        for (auto&i:ids){
            for (auto it = active_set.lower_bound(p[i].x) ; it != active_set.end(); active_set.erase(it++)){
                int j = it->second;
                if (p[i].x-p[i].y > p[j].x-p[j].y) break;
                edg.push_back({ d(p[i] , p[j]) , min(i,j) , max(i,j) });
            }
            active_set[p[i].x] = i;
        }
 
        for (auto& i : ids) {
            if (turn&1) p[i].x *= -1; else swap(p[i].x,p[i].y);
        }
    }
    return;
}
 
int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    SETIO("");
 
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> p[i].x >> p[i].y;
    MST();
    sort(edg.begin(),edg.end());
    if (fixbug){
        for (auto& x : edg) cout << x.d << ' ' << x.x << ' ' << x.y << '\n';
    }
    int i = 0 , cur = 0 , step = 0;
    while (k>0){
            if (i >= edg.size()) break;
            cout << edg[i].d << '\n';
            while (cur < edg.size() && edg[i].x == edg[cur].x && edg[i].y == edg[cur].y) ++cur;
            i = cur;
            --k;
        }
    while (k>0){
        cout << edg.back().d << '\n';
        --k;
    }
}

Compilation message

road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:74:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if (i >= edg.size()) break;
      |                 ~~^~~~~~~~~~~~~
road_construction.cpp:76:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             while (cur < edg.size() && edg[i].x == edg[cur].x && edg[i].y == edg[cur].y) ++cur;
      |                    ~~~~^~~~~~~~~~~~
road_construction.cpp:72:27: warning: unused variable 'step' [-Wunused-variable]
   72 |     int i = 0 , cur = 0 , step = 0;
      |                           ^~~~
road_construction.cpp: In function 'void SETIO(std::string)':
road_construction.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen((name+".inp").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen((name+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 291 ms 33620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 30992 KB Output is correct
2 Correct 423 ms 30896 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 274 ms 36636 KB Output is correct
5 Correct 376 ms 36372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 30992 KB Output is correct
2 Correct 423 ms 30896 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 274 ms 36636 KB Output is correct
5 Correct 376 ms 36372 KB Output is correct
6 Correct 428 ms 36080 KB Output is correct
7 Correct 437 ms 36240 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -