답안 #970312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970312 2024-04-26T10:52:50 Z mychecksedad 분수 공원 (IOI21_parks) C++17
5 / 100
59 ms 21064 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n';
#define ll long long int
const int N = 3e5+10;

struct Dsu{
    vector<int> s, p;
    Dsu(int n){
        s.resize(n, 1);
        p.resize(n);
        for(int i = 0; i < n; ++i) p[i] = i;
    }
    int find(int v){
        if(p[v] == v) return v;
        return p[v] = find(p[v]);
    }
    void merge(int a, int b){
        a = find(a);
        b = find(b);
        if(a != b){
            if(s[a] > s[b]) swap(a, b);
            p[a] = b;
            s[b] += s[a];
        }
    }
};


int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
    build({}, {}, {}, {});
        return 1;
    }
    int n = x.size();
    vector<int> u, v, a, b;

    Dsu d(n);


    vector<pair<int, int>> L, R, M;
    for(int i = 0; i < n; ++i){
        if(x[i] == 2) L.pb({y[i], i}); 
        else if(x[i] == 6) R.pb({y[i], i});
        else M.pb({y[i], i});
    }
    sort(all(L));
    sort(all(R));
    sort(all(M));
    for(int i = 0; i + 1 < L.size(); ++i){
        if(L[i].first < L[i + 1].first - 2) continue;
        u.pb(L[i].second);
        v.pb(L[i + 1].second);
        a.pb(1);
        b.pb(L[i + 1].first + L[i].first>>1);
        d.merge(L[i].second, L[i + 1].second);
    }
    for(int i = 0; i + 1 < R.size(); ++i){
        if(R[i].first < R[i + 1].first - 2) continue;
        u.pb(R[i].second);
        v.pb(R[i + 1].second);
        a.pb(7);
        b.pb(R[i + 1].first + R[i].first>>1);
        d.merge(R[i].second, R[i + 1].second);
    }
    for(int i = 0; i + 1 < M.size(); ++i){
        if(M[i].first < M[i + 1].first - 2) continue;
        u.pb(M[i].second);
        v.pb(M[i + 1].second);
        a.pb((M[i].first/2)%2 == 0 ? 5 : 3);
        b.pb(M[i + 1].first + M[i].first>>1);
        d.merge(M[i].second, M[i + 1].second);
    }

    int p = 0, last = -5;
    for(int i = 0; i < M.size(); ++i){
        while(p < R.size() && R[p].first < M[i].first) ++p;
        if(R[p].first == M[i].first){
            if(last + 2 == M[i].first) continue;
            last = M[i].first;
            u.pb(R[p].second);
            v.pb(M[i].second);
            a.pb(5);
            b.pb(M[i].first + ((M[i].first/2) % 2 == 0 ? -1 : 1));
            d.merge(R[p].second, M[i].second);
        }
    }
    p = 0, last = -5;
    for(int i = 0; i < M.size(); ++i){
        while(p < L.size() && L[p].first < M[i].first) ++p;
        if(L[p].first == M[i].first){
            if(last + 2 == M[i].first) continue;
            last = M[i].first;
            u.pb(L[p].second);
            v.pb(M[i].second);
            a.pb(3);
            b.pb(M[i].first + ((M[i].first/2) % 2 == 0 ? 1 : -1));
            d.merge(L[p].second, M[i].second);
        }
    }


    if(d.s[d.find(0)] < n) return 0;
    build(u, v, a, b);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i = 0; i + 1 < L.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:58:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |         b.pb(L[i + 1].first + L[i].first>>1);
parks.cpp:61:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 0; i + 1 < R.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:66:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |         b.pb(R[i + 1].first + R[i].first>>1);
parks.cpp:69:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(int i = 0; i + 1 < M.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:74:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |         b.pb(M[i + 1].first + M[i].first>>1);
parks.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 0; i < M.size(); ++i){
      |                    ~~^~~~~~~~~~
parks.cpp:80:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         while(p < R.size() && R[p].first < M[i].first) ++p;
      |               ~~^~~~~~~~~~
parks.cpp:92:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int i = 0; i < M.size(); ++i){
      |                    ~~^~~~~~~~~~
parks.cpp:93:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |         while(p < L.size() && L[p].first < M[i].first) ++p;
      |               ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 8652 KB Output is correct
10 Correct 6 ms 1288 KB Output is correct
11 Correct 22 ms 4692 KB Output is correct
12 Correct 6 ms 1764 KB Output is correct
13 Correct 8 ms 3024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 57 ms 8516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 8652 KB Output is correct
10 Correct 6 ms 1288 KB Output is correct
11 Correct 22 ms 4692 KB Output is correct
12 Correct 6 ms 1764 KB Output is correct
13 Correct 8 ms 3024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 57 ms 8516 KB Output is correct
17 Runtime error 0 ms 344 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 8652 KB Output is correct
10 Correct 6 ms 1288 KB Output is correct
11 Correct 22 ms 4692 KB Output is correct
12 Correct 6 ms 1764 KB Output is correct
13 Correct 8 ms 3024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 57 ms 8516 KB Output is correct
17 Runtime error 0 ms 344 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 8652 KB Output is correct
10 Correct 6 ms 1288 KB Output is correct
11 Correct 22 ms 4692 KB Output is correct
12 Correct 6 ms 1764 KB Output is correct
13 Correct 8 ms 3024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 57 ms 8516 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 8652 KB Output is correct
10 Correct 6 ms 1288 KB Output is correct
11 Correct 22 ms 4692 KB Output is correct
12 Correct 6 ms 1764 KB Output is correct
13 Correct 8 ms 3024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 57 ms 8516 KB Output is correct
17 Incorrect 59 ms 21064 KB Wrong answer detected in grader
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 47 ms 8652 KB Output is correct
10 Correct 6 ms 1288 KB Output is correct
11 Correct 22 ms 4692 KB Output is correct
12 Correct 6 ms 1764 KB Output is correct
13 Correct 8 ms 3024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 57 ms 8516 KB Output is correct
17 Runtime error 0 ms 344 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -