답안 #819892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819892 2023-08-10T15:02:00 Z Marco_Escandon 분수 공원 (IOI21_parks) C++17
30 / 100
94 ms 23328 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]-1);
            v.push_back(cad[4][i]-1);
            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;
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 47 ms 9784 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 23 ms 5468 KB Output is correct
12 Correct 6 ms 1944 KB Output is correct
13 Correct 7 ms 3284 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 9784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 47 ms 9784 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 23 ms 5468 KB Output is correct
12 Correct 6 ms 1944 KB Output is correct
13 Correct 7 ms 3284 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 9784 KB Output is correct
17 Correct 1 ms 340 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 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 82 ms 19236 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 37 ms 7968 KB Output is correct
29 Correct 48 ms 11732 KB Output is correct
30 Correct 65 ms 15500 KB Output is correct
31 Correct 82 ms 19248 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 41 ms 10428 KB Output is correct
46 Correct 61 ms 14980 KB Output is correct
47 Correct 60 ms 15020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 47 ms 9784 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 23 ms 5468 KB Output is correct
12 Correct 6 ms 1944 KB Output is correct
13 Correct 7 ms 3284 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 9784 KB Output is correct
17 Correct 1 ms 340 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 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 82 ms 19236 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 37 ms 7968 KB Output is correct
29 Correct 48 ms 11732 KB Output is correct
30 Correct 65 ms 15500 KB Output is correct
31 Correct 82 ms 19248 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 41 ms 10428 KB Output is correct
46 Correct 61 ms 14980 KB Output is correct
47 Correct 60 ms 15020 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 82 ms 20772 KB Output is correct
56 Correct 1 ms 308 KB Output is correct
57 Correct 2 ms 452 KB Output is correct
58 Correct 4 ms 964 KB Output is correct
59 Correct 3 ms 1216 KB Output is correct
60 Correct 40 ms 10524 KB Output is correct
61 Correct 55 ms 14108 KB Output is correct
62 Correct 68 ms 17424 KB Output is correct
63 Correct 83 ms 20888 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 83 ms 20900 KB Output is correct
68 Correct 83 ms 20900 KB Output is correct
69 Correct 91 ms 20772 KB Output is correct
70 Correct 2 ms 596 KB Output is correct
71 Correct 2 ms 980 KB Output is correct
72 Correct 41 ms 11452 KB Output is correct
73 Correct 68 ms 17176 KB Output is correct
74 Correct 85 ms 22564 KB Output is correct
75 Correct 94 ms 23328 KB Output is correct
76 Correct 84 ms 20900 KB Output is correct
77 Correct 2 ms 724 KB Output is correct
78 Correct 2 ms 1108 KB Output is correct
79 Correct 50 ms 11680 KB Output is correct
80 Correct 66 ms 17444 KB Output is correct
81 Correct 91 ms 23200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 47 ms 9784 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 23 ms 5468 KB Output is correct
12 Correct 6 ms 1944 KB Output is correct
13 Correct 7 ms 3284 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 9784 KB Output is correct
17 Runtime error 1 ms 340 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 47 ms 9784 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 23 ms 5468 KB Output is correct
12 Correct 6 ms 1944 KB Output is correct
13 Correct 7 ms 3284 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 9784 KB Output is correct
17 Runtime error 28 ms 6744 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 ms 212 KB Output is correct
9 Correct 47 ms 9784 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 23 ms 5468 KB Output is correct
12 Correct 6 ms 1944 KB Output is correct
13 Correct 7 ms 3284 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 9784 KB Output is correct
17 Correct 1 ms 340 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 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 82 ms 19236 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 37 ms 7968 KB Output is correct
29 Correct 48 ms 11732 KB Output is correct
30 Correct 65 ms 15500 KB Output is correct
31 Correct 82 ms 19248 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 596 KB Output is correct
45 Correct 41 ms 10428 KB Output is correct
46 Correct 61 ms 14980 KB Output is correct
47 Correct 60 ms 15020 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 82 ms 20772 KB Output is correct
56 Correct 1 ms 308 KB Output is correct
57 Correct 2 ms 452 KB Output is correct
58 Correct 4 ms 964 KB Output is correct
59 Correct 3 ms 1216 KB Output is correct
60 Correct 40 ms 10524 KB Output is correct
61 Correct 55 ms 14108 KB Output is correct
62 Correct 68 ms 17424 KB Output is correct
63 Correct 83 ms 20888 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 83 ms 20900 KB Output is correct
68 Correct 83 ms 20900 KB Output is correct
69 Correct 91 ms 20772 KB Output is correct
70 Correct 2 ms 596 KB Output is correct
71 Correct 2 ms 980 KB Output is correct
72 Correct 41 ms 11452 KB Output is correct
73 Correct 68 ms 17176 KB Output is correct
74 Correct 85 ms 22564 KB Output is correct
75 Correct 94 ms 23328 KB Output is correct
76 Correct 84 ms 20900 KB Output is correct
77 Correct 2 ms 724 KB Output is correct
78 Correct 2 ms 1108 KB Output is correct
79 Correct 50 ms 11680 KB Output is correct
80 Correct 66 ms 17444 KB Output is correct
81 Correct 91 ms 23200 KB Output is correct
82 Runtime error 1 ms 340 KB Execution killed with signal 11
83 Halted 0 ms 0 KB -