답안 #623184

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623184 2022-08-05T09:50:37 Z Hanksburger 분수 공원 (IOI21_parks) C++17
30 / 100
359 ms 60840 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > vec[200005], edge;
vector<int> adj[200005], U, V, A, B;
map<pair<int, int>, bool> mp;
bool visited[200005];
queue<int> q;
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});
    for (int i=2; i<=2e5; i+=2)
    {
        if (vec[i].empty())
            continue;
        sort(vec[i].begin(), vec[i].end());
        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>=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>=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>=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>=0)
                        edge.push_back({vec[i-2][ind].second, vec[i][k].second});
                }
            }
        }
        else
        {
            if (vec[i-2].size())
            {
                if (vec[i-2][0].first==2)
                    edge.push_back({vec[i-2][0].second, vec[i][0].second});
                if (vec[i-2][vec[i-2].size()-1].first==6)
                    edge.push_back({vec[i-2][vec[i-2].size()-1].second, vec[i][2].second});
                if (vec[i-2].size()==1 && vec[i-2][0].first==4)
                    edge.push_back({vec[i-2][0].second, vec[i][1].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});
        }
    }
    for (int i=0; i<edge.size(); i++)
    {
        int u=edge[i].first, v=edge[i].second;
        adj[u].push_back(v);
        adj[v].push_back(u);
        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;
            }
        }
    }
    q.push(0);
    visited[0]=1;
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
        for (int v:adj[u])
        {
            if (!visited[v])
            {
                q.push(v);
                visited[v]=1;
            }
        }
    }
    for (int i=0; i<N; i++)
        if (!visited[i])
            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:22:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |             for (int j=0; j<vec[i-2].size(); j++)
      |                           ~^~~~~~~~~~~~~~~~
parks.cpp:38: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]
   38 |                 for (int j=0; j<vec[i-2].size(); j++)
      |                               ~^~~~~~~~~~~~~~~~
parks.cpp:57: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]
   57 |                 for (int j=0; j<vec[i-2].size(); j++)
      |                               ~^~~~~~~~~~~~~~~~
parks.cpp:73: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]
   73 |                     for (int j=0; j<vec[i-2].size(); j++)
      |                                   ~^~~~~~~~~~~~~~~~
parks.cpp:109: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]
  109 |     for (int i=0; i<edge.size(); i++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9592 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 131 ms 30732 KB Output is correct
10 Correct 15 ms 11856 KB Output is correct
11 Correct 56 ms 21000 KB Output is correct
12 Correct 23 ms 12948 KB Output is correct
13 Correct 33 ms 17084 KB Output is correct
14 Correct 9 ms 9968 KB Output is correct
15 Correct 8 ms 9940 KB Output is correct
16 Correct 149 ms 30716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9592 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 131 ms 30732 KB Output is correct
10 Correct 15 ms 11856 KB Output is correct
11 Correct 56 ms 21000 KB Output is correct
12 Correct 23 ms 12948 KB Output is correct
13 Correct 33 ms 17084 KB Output is correct
14 Correct 9 ms 9968 KB Output is correct
15 Correct 8 ms 9940 KB Output is correct
16 Correct 149 ms 30716 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 302 ms 48900 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 7 ms 9940 KB Output is correct
26 Correct 8 ms 10068 KB Output is correct
27 Correct 8 ms 10196 KB Output is correct
28 Correct 112 ms 25400 KB Output is correct
29 Correct 154 ms 33040 KB Output is correct
30 Correct 231 ms 41168 KB Output is correct
31 Correct 284 ms 48796 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 6 ms 9684 KB Output is correct
34 Correct 6 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 7 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 6 ms 9684 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 7 ms 9940 KB Output is correct
44 Correct 7 ms 10068 KB Output is correct
45 Correct 119 ms 29780 KB Output is correct
46 Correct 191 ms 39372 KB Output is correct
47 Correct 186 ms 39168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9592 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 131 ms 30732 KB Output is correct
10 Correct 15 ms 11856 KB Output is correct
11 Correct 56 ms 21000 KB Output is correct
12 Correct 23 ms 12948 KB Output is correct
13 Correct 33 ms 17084 KB Output is correct
14 Correct 9 ms 9968 KB Output is correct
15 Correct 8 ms 9940 KB Output is correct
16 Correct 149 ms 30716 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 302 ms 48900 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 7 ms 9940 KB Output is correct
26 Correct 8 ms 10068 KB Output is correct
27 Correct 8 ms 10196 KB Output is correct
28 Correct 112 ms 25400 KB Output is correct
29 Correct 154 ms 33040 KB Output is correct
30 Correct 231 ms 41168 KB Output is correct
31 Correct 284 ms 48796 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 6 ms 9684 KB Output is correct
34 Correct 6 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 7 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 6 ms 9684 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 7 ms 9940 KB Output is correct
44 Correct 7 ms 10068 KB Output is correct
45 Correct 119 ms 29780 KB Output is correct
46 Correct 191 ms 39372 KB Output is correct
47 Correct 186 ms 39168 KB Output is correct
48 Correct 7 ms 9620 KB Output is correct
49 Correct 5 ms 9684 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 7 ms 9696 KB Output is correct
53 Correct 6 ms 9580 KB Output is correct
54 Correct 8 ms 9684 KB Output is correct
55 Correct 356 ms 60840 KB Output is correct
56 Correct 5 ms 9684 KB Output is correct
57 Correct 7 ms 10068 KB Output is correct
58 Correct 15 ms 11092 KB Output is correct
59 Correct 13 ms 11440 KB Output is correct
60 Correct 177 ms 35068 KB Output is correct
61 Correct 220 ms 42460 KB Output is correct
62 Correct 274 ms 49760 KB Output is correct
63 Correct 359 ms 60752 KB Output is correct
64 Correct 7 ms 9684 KB Output is correct
65 Correct 6 ms 9684 KB Output is correct
66 Correct 6 ms 9684 KB Output is correct
67 Correct 305 ms 48768 KB Output is correct
68 Correct 331 ms 50432 KB Output is correct
69 Correct 318 ms 50436 KB Output is correct
70 Correct 8 ms 10324 KB Output is correct
71 Correct 12 ms 10964 KB Output is correct
72 Correct 142 ms 29972 KB Output is correct
73 Correct 229 ms 40892 KB Output is correct
74 Correct 303 ms 50892 KB Output is correct
75 Correct 322 ms 55820 KB Output is correct
76 Correct 292 ms 50464 KB Output is correct
77 Correct 9 ms 10452 KB Output is correct
78 Correct 12 ms 11248 KB Output is correct
79 Correct 128 ms 31276 KB Output is correct
80 Correct 268 ms 42896 KB Output is correct
81 Correct 285 ms 53548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9592 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 131 ms 30732 KB Output is correct
10 Correct 15 ms 11856 KB Output is correct
11 Correct 56 ms 21000 KB Output is correct
12 Correct 23 ms 12948 KB Output is correct
13 Correct 33 ms 17084 KB Output is correct
14 Correct 9 ms 9968 KB Output is correct
15 Correct 8 ms 9940 KB Output is correct
16 Correct 149 ms 30716 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 7 ms 9684 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Incorrect 290 ms 49788 KB Pair u[199994]=722 @(8, 199996) and v[199994]=70454 @(6, 199998) does not form a valid edge (distance != 2)
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9592 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 131 ms 30732 KB Output is correct
10 Correct 15 ms 11856 KB Output is correct
11 Correct 56 ms 21000 KB Output is correct
12 Correct 23 ms 12948 KB Output is correct
13 Correct 33 ms 17084 KB Output is correct
14 Correct 9 ms 9968 KB Output is correct
15 Correct 8 ms 9940 KB Output is correct
16 Correct 149 ms 30716 KB Output is correct
17 Incorrect 129 ms 27000 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 6 ms 9592 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 131 ms 30732 KB Output is correct
10 Correct 15 ms 11856 KB Output is correct
11 Correct 56 ms 21000 KB Output is correct
12 Correct 23 ms 12948 KB Output is correct
13 Correct 33 ms 17084 KB Output is correct
14 Correct 9 ms 9968 KB Output is correct
15 Correct 8 ms 9940 KB Output is correct
16 Correct 149 ms 30716 KB Output is correct
17 Correct 5 ms 9684 KB Output is correct
18 Correct 6 ms 9684 KB Output is correct
19 Correct 6 ms 9684 KB Output is correct
20 Correct 5 ms 9684 KB Output is correct
21 Correct 5 ms 9684 KB Output is correct
22 Correct 6 ms 9684 KB Output is correct
23 Correct 302 ms 48900 KB Output is correct
24 Correct 5 ms 9684 KB Output is correct
25 Correct 7 ms 9940 KB Output is correct
26 Correct 8 ms 10068 KB Output is correct
27 Correct 8 ms 10196 KB Output is correct
28 Correct 112 ms 25400 KB Output is correct
29 Correct 154 ms 33040 KB Output is correct
30 Correct 231 ms 41168 KB Output is correct
31 Correct 284 ms 48796 KB Output is correct
32 Correct 5 ms 9684 KB Output is correct
33 Correct 6 ms 9684 KB Output is correct
34 Correct 6 ms 9684 KB Output is correct
35 Correct 5 ms 9684 KB Output is correct
36 Correct 5 ms 9684 KB Output is correct
37 Correct 5 ms 9684 KB Output is correct
38 Correct 6 ms 9684 KB Output is correct
39 Correct 7 ms 9684 KB Output is correct
40 Correct 6 ms 9684 KB Output is correct
41 Correct 6 ms 9684 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 7 ms 9940 KB Output is correct
44 Correct 7 ms 10068 KB Output is correct
45 Correct 119 ms 29780 KB Output is correct
46 Correct 191 ms 39372 KB Output is correct
47 Correct 186 ms 39168 KB Output is correct
48 Correct 7 ms 9620 KB Output is correct
49 Correct 5 ms 9684 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 5 ms 9684 KB Output is correct
52 Correct 7 ms 9696 KB Output is correct
53 Correct 6 ms 9580 KB Output is correct
54 Correct 8 ms 9684 KB Output is correct
55 Correct 356 ms 60840 KB Output is correct
56 Correct 5 ms 9684 KB Output is correct
57 Correct 7 ms 10068 KB Output is correct
58 Correct 15 ms 11092 KB Output is correct
59 Correct 13 ms 11440 KB Output is correct
60 Correct 177 ms 35068 KB Output is correct
61 Correct 220 ms 42460 KB Output is correct
62 Correct 274 ms 49760 KB Output is correct
63 Correct 359 ms 60752 KB Output is correct
64 Correct 7 ms 9684 KB Output is correct
65 Correct 6 ms 9684 KB Output is correct
66 Correct 6 ms 9684 KB Output is correct
67 Correct 305 ms 48768 KB Output is correct
68 Correct 331 ms 50432 KB Output is correct
69 Correct 318 ms 50436 KB Output is correct
70 Correct 8 ms 10324 KB Output is correct
71 Correct 12 ms 10964 KB Output is correct
72 Correct 142 ms 29972 KB Output is correct
73 Correct 229 ms 40892 KB Output is correct
74 Correct 303 ms 50892 KB Output is correct
75 Correct 322 ms 55820 KB Output is correct
76 Correct 292 ms 50464 KB Output is correct
77 Correct 9 ms 10452 KB Output is correct
78 Correct 12 ms 11248 KB Output is correct
79 Correct 128 ms 31276 KB Output is correct
80 Correct 268 ms 42896 KB Output is correct
81 Correct 285 ms 53548 KB Output is correct
82 Correct 6 ms 9684 KB Output is correct
83 Correct 7 ms 9684 KB Output is correct
84 Correct 6 ms 9684 KB Output is correct
85 Incorrect 290 ms 49788 KB Pair u[199994]=722 @(8, 199996) and v[199994]=70454 @(6, 199998) does not form a valid edge (distance != 2)
86 Halted 0 ms 0 KB -