Submission #970304

# Submission time Handle Problem Language Result Execution time Memory
970304 2024-04-26T10:37:37 Z mychecksedad Fountain Parks (IOI21_parks) C++17
0 / 100
0 ms 348 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;
    for(int i = 0; i < n; ++i){
        if(x[i] == 2) L.pb({y[i], i}); 
        else R.pb({y[i], i});
    }
    sort(all(L));
    sort(all(R));
    for(int i = 0; i + 1 < L.size(); ++i){
        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){
        u.pb(R[i].second);
        v.pb(R[i + 1].second);
        a.pb(5);
        b.pb(R[i + 1].first + R[i].first>>1);
        d.merge(R[i].second, R[i + 1].second);
    }

    if(!R.empty() && !L.empty()){
        int p = 0;
        for(int i = 0; i < L.size(); ++i){
            while(R[p].first < L[i].first) ++p;
            if(L[i].first == R[p].first){
                u.pb(L[i].second);
                v.pb(R[p].second);
                a.pb(3);
                b.pb(L[i].first - 1);
                d.merge(L[i].second, R[p].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:51: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]
   51 |     for(int i = 0; i + 1 < L.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:55:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |         b.pb(L[i + 1].first + L[i].first>>1);
parks.cpp:58: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]
   58 |     for(int i = 0; i + 1 < R.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
parks.cpp:62:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |         b.pb(R[i + 1].first + R[i].first>>1);
parks.cpp:68: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]
   68 |         for(int i = 0; i < L.size(); ++i){
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Pair u[0]=0 @(2, 2) and v[0]=1 @(2, 6) does not form a valid edge (distance != 2)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Pair u[0]=0 @(2, 2) and v[0]=1 @(2, 6) does not form a valid edge (distance != 2)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Pair u[0]=0 @(2, 2) and v[0]=1 @(2, 6) does not form a valid edge (distance != 2)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Pair u[0]=0 @(2, 2) and v[0]=1 @(2, 6) does not form a valid edge (distance != 2)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Pair u[0]=0 @(2, 2) and v[0]=1 @(2, 6) does not form a valid edge (distance != 2)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Pair u[0]=0 @(2, 2) and v[0]=1 @(2, 6) does not form a valid edge (distance != 2)
4 Halted 0 ms 0 KB -