답안 #623162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623162 2022-08-05T09:25:16 Z Hanksburger 분수 공원 (IOI21_parks) C++17
15 / 100
223 ms 39276 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vec[200005], edge;
map<pair<int, int>, bool> mp;
vector<int> U, V, A, B;
int construct_roads(vector<int> X, vector<int> Y)
{
    int N=X.size(), cnt2=0, cnt4=0, cnt6=0;
    for (int i=0; i<N; i++)
    {
        vec[Y[i]].push_back({X[i], i});
        if (X[i]==2)
            cnt2++;
        else if (X[i]==4)
            cnt4++;
        else
            cnt6++;
    }
    if (cnt2 && cnt6 && !cnt4)
        return 0;
    bool ok=0;
    for (int i=2; i<=2e5; i+=2)
    {
        if (vec[i].empty())
            continue;
        sort(vec[i].begin(), vec[i].end());
        if (ok)
        {
            if (vec[i].size()==1)
            {
                int ind=-1;
                for (int j=0; j<vec[i-2].size(); j++)
                {
                    if (vec[i-2][j].first==vec[i][0].first)
                    {
                        ind=j;
                        break;
                    }
                }
                if (ind==-1)
                    return 0;
                edge.push_back({vec[i-2][ind].second, vec[i][0].second});
            }
            else if (vec[i].size()==2)
            {
                if (vec[i][0].first==2 && vec[i][1].first==4)
                {
                    int ind=-1;
                    for (int j=0; j<vec[i-2].size(); j++)
                    {
                        if (vec[i-2][j].first<=4)
                        {
                            ind=j;
                            break;
                        }
                    }
                    if (ind==-1)
                        return 0;
                    if (vec[i-2][ind].first==2)
                        edge.push_back({vec[i-2][ind].second, vec[i][0].second});
                    else
                        edge.push_back({vec[i-2][ind].second, vec[i][1].second});
                }
                else if (vec[i][0].first==4 && vec[i][1].first==6)
                {
                    int ind=-1;
                    for (int j=0; j<vec[i-2].size(); j++)
                        if (vec[i-2][j].first>=4)
                            ind=j;
                    if (ind==-1)
                        return 0;
                    if (vec[i-2][ind].first==4)
                        edge.push_back({vec[i-2][ind].second, vec[i][0].second});
                    else
                        edge.push_back({vec[i-2][ind].second, vec[i][1].second});
                }
                else
                {
                    for (int k=0; k<2; k++)
                    {
                        int ind=-1;
                        for (int j=0; j<vec[i-2].size(); j++)
                        {
                            if (vec[i-2][j].first==vec[i][k].first)
                            {
                                ind=j;
                                break;
                            }
                        }
                        if (ind==-1)
                            return 0;
                        edge.push_back({vec[i-2][ind].second, vec[i][k].second});
                    }
                }
            }
            else
            {
                if (vec[i-2].empty())
                    return 0;
                if (vec[i-2][0].first==2)
                    edge.push_back({vec[i-2][0].second, vec[i][0].second});
                else if (vec[i-2][0].first==4)
                    edge.push_back({vec[i-2][0].second, vec[i][1].second});
                else
                    edge.push_back({vec[i-2][0].second, vec[i][2].second});
            }
        }
        if (vec[i].size()==2)
        {
            if (vec[i][0].first+2==vec[i][1].first)
                edge.push_back({vec[i][0].second, vec[i][1].second});
        }
        else if (vec[i].size()==3)
        {
            edge.push_back({vec[i][0].second, vec[i][1].second});
            edge.push_back({vec[i][1].second, vec[i][2].second});
        }
        ok=1;
    }
    for (int i=0; i<edge.size(); i++)
    {
        int u=edge[i].first, v=edge[i].second;
        U.push_back(u);
        V.push_back(v);
        if (X[u]==X[v])
        {
            if (mp[{X[u]-1, Y[u]+1}])
            {
                A.push_back(X[u]+1);
                B.push_back(Y[u]+1);
                mp[{X[u]+1, Y[u]+1}]=1;
            }
            else
            {
                A.push_back(X[u]-1);
                B.push_back(Y[u]+1);
                mp[{X[u]-1, Y[u]+1}]=1;
            }
        }
        else
        {
            if (mp[{X[u]+1, Y[u]-1}])
            {
                A.push_back(X[u]+1);
                B.push_back(Y[u]+1);
                mp[{X[u]+1, Y[u]+1}]=1;
            }
            else
            {
                A.push_back(X[u]+1);
                B.push_back(Y[u]-1);
                mp[{X[u]+1, Y[u]-1}]=1;
            }
        }
    }
    build(U, V, A, B);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:33:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 for (int j=0; j<vec[i-2].size(); j++)
      |                               ~^~~~~~~~~~~~~~~~
parks.cpp:50:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                     for (int j=0; j<vec[i-2].size(); j++)
      |                                   ~^~~~~~~~~~~~~~~~
parks.cpp:68:36: 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 j=0; j<vec[i-2].size(); j++)
      |                                   ~^~~~~~~~~~~~~~~~
parks.cpp:83:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |                         for (int j=0; j<vec[i-2].size(); j++)
      |                                       ~^~~~~~~~~~~~~~~~
parks.cpp:121:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for (int i=0; i<edge.size(); i++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 100 ms 22820 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 47 ms 14628 KB Output is correct
12 Correct 14 ms 7748 KB Output is correct
13 Correct 11 ms 7380 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 95 ms 22792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 100 ms 22820 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 47 ms 14628 KB Output is correct
12 Correct 14 ms 7748 KB Output is correct
13 Correct 11 ms 7380 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 95 ms 22792 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 214 ms 37808 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 78 ms 17992 KB Output is correct
29 Correct 119 ms 24480 KB Output is correct
30 Correct 168 ms 31364 KB Output is correct
31 Correct 208 ms 37736 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4992 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 92 ms 21900 KB Output is correct
46 Correct 134 ms 29960 KB Output is correct
47 Correct 133 ms 29904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 100 ms 22820 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 47 ms 14628 KB Output is correct
12 Correct 14 ms 7748 KB Output is correct
13 Correct 11 ms 7380 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 95 ms 22792 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 214 ms 37808 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 78 ms 17992 KB Output is correct
29 Correct 119 ms 24480 KB Output is correct
30 Correct 168 ms 31364 KB Output is correct
31 Correct 208 ms 37736 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4992 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 92 ms 21900 KB Output is correct
46 Correct 134 ms 29960 KB Output is correct
47 Correct 133 ms 29904 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4888 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 208 ms 38064 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 8 ms 5972 KB Output is correct
59 Correct 5 ms 5332 KB Output is correct
60 Correct 116 ms 21348 KB Output is correct
61 Correct 153 ms 28372 KB Output is correct
62 Correct 182 ms 32588 KB Output is correct
63 Correct 223 ms 38124 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Incorrect 220 ms 39276 KB Given structure is not connected: There is no path between vertices 0 and 3
68 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 100 ms 22820 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 47 ms 14628 KB Output is correct
12 Correct 14 ms 7748 KB Output is correct
13 Correct 11 ms 7380 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 95 ms 22792 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 4 ms 4948 KB Solution announced impossible, but it is possible.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 100 ms 22820 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 47 ms 14628 KB Output is correct
12 Correct 14 ms 7748 KB Output is correct
13 Correct 11 ms 7380 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 95 ms 22792 KB Output is correct
17 Incorrect 137 ms 23060 KB Given structure is not connected: There is no path between vertices 0 and 1
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 4 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 100 ms 22820 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 47 ms 14628 KB Output is correct
12 Correct 14 ms 7748 KB Output is correct
13 Correct 11 ms 7380 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 95 ms 22792 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 2 ms 4948 KB Output is correct
19 Correct 3 ms 4948 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 214 ms 37808 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 5076 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 78 ms 17992 KB Output is correct
29 Correct 119 ms 24480 KB Output is correct
30 Correct 168 ms 31364 KB Output is correct
31 Correct 208 ms 37736 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 2 ms 4948 KB Output is correct
37 Correct 3 ms 4992 KB Output is correct
38 Correct 2 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 3 ms 4948 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 3 ms 5076 KB Output is correct
44 Correct 3 ms 5076 KB Output is correct
45 Correct 92 ms 21900 KB Output is correct
46 Correct 134 ms 29960 KB Output is correct
47 Correct 133 ms 29904 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4888 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 208 ms 38064 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 4 ms 5204 KB Output is correct
58 Correct 8 ms 5972 KB Output is correct
59 Correct 5 ms 5332 KB Output is correct
60 Correct 116 ms 21348 KB Output is correct
61 Correct 153 ms 28372 KB Output is correct
62 Correct 182 ms 32588 KB Output is correct
63 Correct 223 ms 38124 KB Output is correct
64 Correct 3 ms 4948 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 3 ms 4948 KB Output is correct
67 Incorrect 220 ms 39276 KB Given structure is not connected: There is no path between vertices 0 and 3
68 Halted 0 ms 0 KB -