답안 #623161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623161 2022-08-05T09:22:33 Z Hanksburger 분수 공원 (IOI21_parks) C++17
15 / 100
243 ms 39804 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();
    for (int i=0; i<N; i++)
        vec[Y[i]].push_back({X[i], i});
    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:23: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]
   23 |                 for (int j=0; j<vec[i-2].size(); j++)
      |                               ~^~~~~~~~~~~~~~~~
parks.cpp:40: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]
   40 |                     for (int j=0; j<vec[i-2].size(); j++)
      |                                   ~^~~~~~~~~~~~~~~~
parks.cpp:58: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]
   58 |                     for (int j=0; j<vec[i-2].size(); j++)
      |                                   ~^~~~~~~~~~~~~~~~
parks.cpp:73: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]
   73 |                         for (int j=0; j<vec[i-2].size(); j++)
      |                                       ~^~~~~~~~~~~~~~~~
parks.cpp:111: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]
  111 |     for (int i=0; i<edge.size(); i++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 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 102 ms 23612 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 48 ms 14912 KB Output is correct
12 Correct 15 ms 7764 KB Output is correct
13 Correct 17 ms 7832 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 116 ms 23628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 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 102 ms 23612 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 48 ms 14912 KB Output is correct
12 Correct 15 ms 7764 KB Output is correct
13 Correct 17 ms 7832 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 116 ms 23628 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 5 ms 5000 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 243 ms 39436 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 6 ms 5204 KB Output is correct
26 Correct 6 ms 5048 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 99 ms 18616 KB Output is correct
29 Correct 125 ms 25452 KB Output is correct
30 Correct 180 ms 32684 KB Output is correct
31 Correct 229 ms 39464 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 5004 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5000 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 5000 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 5144 KB Output is correct
45 Correct 89 ms 22720 KB Output is correct
46 Correct 143 ms 31056 KB Output is correct
47 Correct 133 ms 31084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 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 102 ms 23612 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 48 ms 14912 KB Output is correct
12 Correct 15 ms 7764 KB Output is correct
13 Correct 17 ms 7832 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 116 ms 23628 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 5 ms 5000 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 243 ms 39436 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 6 ms 5204 KB Output is correct
26 Correct 6 ms 5048 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 99 ms 18616 KB Output is correct
29 Correct 125 ms 25452 KB Output is correct
30 Correct 180 ms 32684 KB Output is correct
31 Correct 229 ms 39464 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 5004 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5000 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 5000 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 5144 KB Output is correct
45 Correct 89 ms 22720 KB Output is correct
46 Correct 143 ms 31056 KB Output is correct
47 Correct 133 ms 31084 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 4 ms 4996 KB Output is correct
51 Correct 4 ms 5000 KB Output is correct
52 Correct 3 ms 4976 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 5004 KB Output is correct
55 Correct 205 ms 39704 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 6100 KB Output is correct
59 Correct 5 ms 5416 KB Output is correct
60 Correct 110 ms 22108 KB Output is correct
61 Correct 135 ms 29292 KB Output is correct
62 Correct 175 ms 33944 KB Output is correct
63 Correct 211 ms 39804 KB Output is correct
64 Incorrect 3 ms 4948 KB Given structure is not connected: There is no path between vertices 0 and 1
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 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 102 ms 23612 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 48 ms 14912 KB Output is correct
12 Correct 15 ms 7764 KB Output is correct
13 Correct 17 ms 7832 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 116 ms 23628 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Solution announced impossible, but it is possible.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 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 102 ms 23612 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 48 ms 14912 KB Output is correct
12 Correct 15 ms 7764 KB Output is correct
13 Correct 17 ms 7832 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 116 ms 23628 KB Output is correct
17 Incorrect 138 ms 25072 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 3 ms 5000 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 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 102 ms 23612 KB Output is correct
10 Correct 10 ms 6868 KB Output is correct
11 Correct 48 ms 14912 KB Output is correct
12 Correct 15 ms 7764 KB Output is correct
13 Correct 17 ms 7832 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 116 ms 23628 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 4996 KB Output is correct
20 Correct 5 ms 5000 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
23 Correct 243 ms 39436 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 6 ms 5204 KB Output is correct
26 Correct 6 ms 5048 KB Output is correct
27 Correct 4 ms 5076 KB Output is correct
28 Correct 99 ms 18616 KB Output is correct
29 Correct 125 ms 25452 KB Output is correct
30 Correct 180 ms 32684 KB Output is correct
31 Correct 229 ms 39464 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 5004 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 5000 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 4 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 5000 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 5144 KB Output is correct
45 Correct 89 ms 22720 KB Output is correct
46 Correct 143 ms 31056 KB Output is correct
47 Correct 133 ms 31084 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 4 ms 4996 KB Output is correct
51 Correct 4 ms 5000 KB Output is correct
52 Correct 3 ms 4976 KB Output is correct
53 Correct 3 ms 4948 KB Output is correct
54 Correct 3 ms 5004 KB Output is correct
55 Correct 205 ms 39704 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 6100 KB Output is correct
59 Correct 5 ms 5416 KB Output is correct
60 Correct 110 ms 22108 KB Output is correct
61 Correct 135 ms 29292 KB Output is correct
62 Correct 175 ms 33944 KB Output is correct
63 Correct 211 ms 39804 KB Output is correct
64 Incorrect 3 ms 4948 KB Given structure is not connected: There is no path between vertices 0 and 1
65 Halted 0 ms 0 KB -