답안 #1050873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050873 2024-08-09T15:58:31 Z amine_aroua 분수 공원 (IOI21_parks) C++17
30 / 100
1819 ms 63176 KB
#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<bool> vis;
void dfs(int i)
{
    if(vis[i])
        return;
    vis[i] = 1;
    for(auto j : adj[i])
    {
        dfs(j);
    }
}
void add_edge(int u , int v)
{
    adj[u].push_back(v);
    adj[v].push_back(u);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int construct_roads(std::vector<int> x, std::vector<int> y) {
    int n= (int)x.size();
    adj.assign(n , {});
    vis.assign(n , 0);
    vector<int> u , v , a , b;
    map<pair<int, int> , int> idx;
    set<pair<int ,int>> taken;
    for(int i = 0 ; i <n ; i++)
    {
        idx[{x[i] , y[i]}] = i;
    }
    vector<pair<int ,int>> vv;
    for(int i = 0 ; i < n ; i++)
        vv.push_back({x[i] , y[i]});
    sort(vv.begin() , vv.end());
    int cnt = 20;
    while(cnt--)
    {
        u.clear();
        v.clear();
        a.clear();
        b.clear();
        taken.clear();
        adj.assign(n , {});
        vis.assign(n ,0);

        for(int i = 0 ; i < n ;i++)
        {
            x[i] = vv[i].first , y[i] = vv[i].second;
        }
        bool acc = 1;
        for(int i = 0 ; i < n ;i++)
        {
            if(idx.count({x[i] + 2 , y[i]}))
            {
                if(!taken.count({x[i] + 1 , y[i] - 1}))
                {
                    u.push_back(idx[{x[i] , y[i]}]);
                    v.push_back(idx[{x[i] + 2 , y[i]}]);
                    a.push_back(x[i] + 1);
                    b.push_back(y[i] - 1);
                    taken.insert({x[i] + 1 , y[i] - 1});
                }
                else if(!taken.count({x[i] + 1 , y[i] + 1}))
                {
                    u.push_back(idx[{x[i] , y[i]}]);
                    v.push_back(idx[{x[i] + 2 , y[i]}]);
                    a.push_back(x[i] + 1);
                    b.push_back(y[i] + 1);
                    taken.insert({x[i] + 1 , y[i] + 1});
                }
            }
            if(idx.count({x[i] , y[i] + 2}))
            {
                
                if(!taken.count({x[i] - 1 , y[i] + 1}))
                {
                    u.push_back(idx[{x[i] , y[i]}]);
                    v.push_back(idx[{x[i] , y[i] + 2}]);
                    b.push_back(y[i] + 1);
                    a.push_back(x[i] - 1);
                    taken.insert({x[i] - 1 , y[i] +1});
                }
                else if(!taken.count({x[i] + 1 , y[i] + 1}))
                {
                    u.push_back(idx[{x[i] , y[i]}]);
                    v.push_back(idx[{x[i] , y[i] + 2}]);
                    b.push_back(y[i] + 1);
                    a.push_back(x[i] + 1);
                    taken.insert({x[i] + 1 , y[i] +1});
                }
            }
        }
        for(int i = 0 ; i < (int)u.size() ; i++)
        {
            add_edge(u[i] , v[i]);
        }
        dfs(0);
        for(int i = 0 ; i < n ; i++)
        {
            if(!vis[i])
            {
                acc = 0;
                break;
            }
        }
        if(!acc)
        {
            continue;
            shuffle(v.begin() , v.end() , rng);
        }
        build(u , v , a , b);
        return 1;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 105 ms 27276 KB Output is correct
10 Correct 8 ms 3156 KB Output is correct
11 Correct 49 ms 14860 KB Output is correct
12 Correct 12 ms 4724 KB Output is correct
13 Correct 339 ms 10456 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
16 Correct 104 ms 26132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 105 ms 27276 KB Output is correct
10 Correct 8 ms 3156 KB Output is correct
11 Correct 49 ms 14860 KB Output is correct
12 Correct 12 ms 4724 KB Output is correct
13 Correct 339 ms 10456 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
16 Correct 104 ms 26132 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 305 ms 63176 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 27 ms 1116 KB Output is correct
27 Correct 30 ms 1372 KB Output is correct
28 Correct 102 ms 26588 KB Output is correct
29 Correct 175 ms 38344 KB Output is correct
30 Correct 249 ms 53236 KB Output is correct
31 Correct 335 ms 62664 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 11 ms 868 KB Output is correct
44 Correct 22 ms 856 KB Output is correct
45 Correct 104 ms 26276 KB Output is correct
46 Correct 167 ms 38620 KB Output is correct
47 Correct 162 ms 38748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 105 ms 27276 KB Output is correct
10 Correct 8 ms 3156 KB Output is correct
11 Correct 49 ms 14860 KB Output is correct
12 Correct 12 ms 4724 KB Output is correct
13 Correct 339 ms 10456 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
16 Correct 104 ms 26132 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 305 ms 63176 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 27 ms 1116 KB Output is correct
27 Correct 30 ms 1372 KB Output is correct
28 Correct 102 ms 26588 KB Output is correct
29 Correct 175 ms 38344 KB Output is correct
30 Correct 249 ms 53236 KB Output is correct
31 Correct 335 ms 62664 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 11 ms 868 KB Output is correct
44 Correct 22 ms 856 KB Output is correct
45 Correct 104 ms 26276 KB Output is correct
46 Correct 167 ms 38620 KB Output is correct
47 Correct 162 ms 38748 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 600 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 303 ms 57628 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 2140 KB Output is correct
59 Correct 81 ms 2756 KB Output is correct
60 Correct 131 ms 30516 KB Output is correct
61 Correct 192 ms 41084 KB Output is correct
62 Correct 229 ms 49312 KB Output is correct
63 Correct 303 ms 58832 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 237 ms 53212 KB Output is correct
68 Correct 269 ms 53384 KB Output is correct
69 Correct 236 ms 53776 KB Output is correct
70 Correct 24 ms 1112 KB Output is correct
71 Correct 53 ms 1884 KB Output is correct
72 Correct 103 ms 25496 KB Output is correct
73 Correct 174 ms 39312 KB Output is correct
74 Correct 233 ms 50824 KB Output is correct
75 Correct 254 ms 58248 KB Output is correct
76 Correct 251 ms 54932 KB Output is correct
77 Correct 33 ms 1368 KB Output is correct
78 Correct 62 ms 2412 KB Output is correct
79 Correct 112 ms 26784 KB Output is correct
80 Correct 185 ms 40588 KB Output is correct
81 Correct 250 ms 54820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 105 ms 27276 KB Output is correct
10 Correct 8 ms 3156 KB Output is correct
11 Correct 49 ms 14860 KB Output is correct
12 Correct 12 ms 4724 KB Output is correct
13 Correct 339 ms 10456 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
16 Correct 104 ms 26132 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 250 ms 55728 KB Output is correct
21 Correct 246 ms 54400 KB Output is correct
22 Correct 246 ms 53640 KB Output is correct
23 Correct 194 ms 45400 KB Output is correct
24 Correct 392 ms 22992 KB Output is correct
25 Correct 1819 ms 41420 KB Output is correct
26 Correct 1576 ms 41256 KB Output is correct
27 Correct 249 ms 48756 KB Output is correct
28 Correct 234 ms 48776 KB Output is correct
29 Correct 248 ms 48772 KB Output is correct
30 Correct 296 ms 48776 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 125 ms 3360 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 105 ms 27276 KB Output is correct
10 Correct 8 ms 3156 KB Output is correct
11 Correct 49 ms 14860 KB Output is correct
12 Correct 12 ms 4724 KB Output is correct
13 Correct 339 ms 10456 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
16 Correct 104 ms 26132 KB Output is correct
17 Correct 256 ms 55288 KB Output is correct
18 Correct 261 ms 55016 KB Output is correct
19 Correct 268 ms 53892 KB Output is correct
20 Correct 263 ms 58860 KB Output is correct
21 Correct 222 ms 48164 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 271 ms 7216 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 404 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 105 ms 27276 KB Output is correct
10 Correct 8 ms 3156 KB Output is correct
11 Correct 49 ms 14860 KB Output is correct
12 Correct 12 ms 4724 KB Output is correct
13 Correct 339 ms 10456 KB Output is correct
14 Correct 5 ms 604 KB Output is correct
15 Correct 9 ms 604 KB Output is correct
16 Correct 104 ms 26132 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 305 ms 63176 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 600 KB Output is correct
26 Correct 27 ms 1116 KB Output is correct
27 Correct 30 ms 1372 KB Output is correct
28 Correct 102 ms 26588 KB Output is correct
29 Correct 175 ms 38344 KB Output is correct
30 Correct 249 ms 53236 KB Output is correct
31 Correct 335 ms 62664 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 11 ms 868 KB Output is correct
44 Correct 22 ms 856 KB Output is correct
45 Correct 104 ms 26276 KB Output is correct
46 Correct 167 ms 38620 KB Output is correct
47 Correct 162 ms 38748 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 600 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 303 ms 57628 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 860 KB Output is correct
58 Correct 6 ms 2140 KB Output is correct
59 Correct 81 ms 2756 KB Output is correct
60 Correct 131 ms 30516 KB Output is correct
61 Correct 192 ms 41084 KB Output is correct
62 Correct 229 ms 49312 KB Output is correct
63 Correct 303 ms 58832 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 237 ms 53212 KB Output is correct
68 Correct 269 ms 53384 KB Output is correct
69 Correct 236 ms 53776 KB Output is correct
70 Correct 24 ms 1112 KB Output is correct
71 Correct 53 ms 1884 KB Output is correct
72 Correct 103 ms 25496 KB Output is correct
73 Correct 174 ms 39312 KB Output is correct
74 Correct 233 ms 50824 KB Output is correct
75 Correct 254 ms 58248 KB Output is correct
76 Correct 251 ms 54932 KB Output is correct
77 Correct 33 ms 1368 KB Output is correct
78 Correct 62 ms 2412 KB Output is correct
79 Correct 112 ms 26784 KB Output is correct
80 Correct 185 ms 40588 KB Output is correct
81 Correct 250 ms 54820 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 250 ms 55728 KB Output is correct
86 Correct 246 ms 54400 KB Output is correct
87 Correct 246 ms 53640 KB Output is correct
88 Correct 194 ms 45400 KB Output is correct
89 Correct 392 ms 22992 KB Output is correct
90 Correct 1819 ms 41420 KB Output is correct
91 Correct 1576 ms 41256 KB Output is correct
92 Correct 249 ms 48756 KB Output is correct
93 Correct 234 ms 48776 KB Output is correct
94 Correct 248 ms 48772 KB Output is correct
95 Correct 296 ms 48776 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Incorrect 125 ms 3360 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -