Submission #819890

# Submission time Handle Problem Language Result Execution time Memory
819890 2023-08-10T15:00:55 Z Marco_Escandon Fountain Parks (IOI21_parks) C++17
5 / 100
82 ms 19228 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cad[7][200004]={ };


struct UFDS{
    typedef long long ll;
    ll nds;
    vector<ll> P,S;
    void init(ll n){
        nds=n;
        P.resize(n+1);S.resize(n+1);
        for(int i=0; i<=n; i++){
            P[i]=i;
            S[i]=1;
        }
    }
    ll Find_Set(ll i){
        if(P[i]==i)return i;
        else return P[i]=Find_Set(P[i]);
    }
    ll Size_Set(ll i){
        return S[Find_Set(i)];
    }
    void Union_Set(ll a, ll b){
        a=Find_Set(a);
        b=Find_Set(b);
        if(a!=b){
            P[a]=b;
            S[b]+=S[a];
            nds--;
        }
    }
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }
    ll n=x.size();
    for(int i=0; i<n; i++)
    {
        cad[x[i]][y[i]]=i+1;
    }
    UFDS asd;
    asd.init(n);
    n=200001;
    std::vector<int> u, v, a, b;
    ll pl=0;
    for(int i=2; i<n; i+=2)
    {
        if(cad[2][i]!=0&&cad[2][i+2]!=0)
        {
            u.push_back(cad[2][i]-1);
            v.push_back(cad[2][i+2]-1);
            a.push_back(1);
            b.push_back(i+1);
        }
        if(cad[6][i]!=0&&cad[6][i+2]!=0)
        {
            u.push_back(cad[6][i]-1);
            v.push_back(cad[6][i+2]-1);
            a.push_back(7);
            b.push_back(i+1);
        }
    }
    for(int i=2; i<n; i+=2)
    {
        if(cad[4][i]!=0&&cad[4][i+2]==0)
        {
            if(cad[2][i]!=0)
            {
                u.push_back(cad[2][i]-1);
                v.push_back(cad[4][i]-1);
                a.push_back(3);
                b.push_back(i+1);
            }
            if(cad[6][i]!=0)
            {
                u.push_back(cad[4][i]-1);
                v.push_back(cad[6][i]-1);
                a.push_back(5);
                b.push_back(i+1);
            }
        }
        else if(cad[4][i]!=0&&cad[2][i+2]==0&&cad[2][i]!=0&&cad[6][i+2]==0&&cad[6][i]!=0)
        {
            u.push_back(cad[4][i]-1);
            v.push_back(cad[4][i+2]-1);
            a.push_back(3);
            b.push_back(i+1);

            u.push_back(cad[2][i]-1);
            v.push_back(cad[4][i]-1);
            a.push_back(3);
            b.push_back(i-1);


            u.push_back(cad[6][i]-1);
            v.push_back(cad[4][i]-1);
            a.push_back(5);
            b.push_back(i+1);
        }
        else if(cad[4][i]!=0&&cad[2][i+2]==0&&cad[2][i]!=0)
        {
            u.push_back(cad[4][i]-1);
            v.push_back(cad[4][i+2]-1);
            a.push_back(5);
            b.push_back(i+1);
            u.push_back(cad[2][i]);
            v.push_back(cad[4][i]);
            a.push_back(3);
            b.push_back(i+1);
        }
        else if(cad[4][i]!=0&&cad[6][i+2]==0&&cad[6][i]!=0)
        {
            u.push_back(cad[4][i]-1);
            v.push_back(cad[4][i+2]-1);
            a.push_back(3);
            b.push_back(i+1);
            u.push_back(cad[6][i]-1);
            v.push_back(cad[4][i]-1);
            a.push_back(5);
            b.push_back(i+1);
        }
        else if(cad[4][i]!=0&&cad[4][i+2]!=0)
        {
            u.push_back(cad[4][i]-1);
            v.push_back(cad[4][i+2]-1);
            a.push_back(5);
            b.push_back(i+1);
        }
    }
    for(int i=0; i<a.size(); i++)
    {
        asd.Union_Set(v[i],u[i]);
    }
    if(asd.Size_Set(0)!=x.size())
    {
        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:137:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |     for(int i=0; i<a.size(); i++)
      |                  ~^~~~~~~~~
parks.cpp:141:23: warning: comparison of integer expressions of different signedness: 'UFDS::ll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |     if(asd.Size_Set(0)!=x.size())
      |        ~~~~~~~~~~~~~~~^~~~~~~~~~
parks.cpp:52:8: warning: unused variable 'pl' [-Wunused-variable]
   52 |     ll pl=0;
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 39 ms 9788 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 21 ms 5452 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 7 ms 3244 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 40 ms 9780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 39 ms 9788 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 21 ms 5452 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 7 ms 3244 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 40 ms 9780 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 82 ms 19228 KB Output is correct
24 Incorrect 1 ms 212 KB Pair u[4]=4 @(2, 183578) and v[4]=3 @(2, 183572) does not form a valid edge (distance != 2)
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 39 ms 9788 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 21 ms 5452 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 7 ms 3244 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 40 ms 9780 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 82 ms 19228 KB Output is correct
24 Incorrect 1 ms 212 KB Pair u[4]=4 @(2, 183578) and v[4]=3 @(2, 183572) does not form a valid edge (distance != 2)
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 39 ms 9788 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 21 ms 5452 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 7 ms 3244 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 40 ms 9780 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 39 ms 9788 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 21 ms 5452 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 7 ms 3244 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 40 ms 9780 KB Output is correct
17 Runtime error 29 ms 6752 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 39 ms 9788 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 21 ms 5452 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 7 ms 3244 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 40 ms 9780 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 82 ms 19228 KB Output is correct
24 Incorrect 1 ms 212 KB Pair u[4]=4 @(2, 183578) and v[4]=3 @(2, 183572) does not form a valid edge (distance != 2)
25 Halted 0 ms 0 KB -