Submission #1050869

# Submission time Handle Problem Language Result Execution time Memory
1050869 2024-08-09T15:50:12 Z amine_aroua Fountain Parks (IOI21_parks) C++17
30 / 100
307 ms 63180 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 = 1;
    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;
        build(u , v , a , b);
        return 1;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 98 ms 27348 KB Output is correct
10 Correct 8 ms 3160 KB Output is correct
11 Correct 48 ms 14972 KB Output is correct
12 Correct 13 ms 4700 KB Output is correct
13 Correct 32 ms 10276 KB Output is correct
14 Correct 1 ms 652 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 104 ms 25972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 98 ms 27348 KB Output is correct
10 Correct 8 ms 3160 KB Output is correct
11 Correct 48 ms 14972 KB Output is correct
12 Correct 13 ms 4700 KB Output is correct
13 Correct 32 ms 10276 KB Output is correct
14 Correct 1 ms 652 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 104 ms 25972 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 384 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 348 KB Output is correct
23 Correct 299 ms 63180 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 3 ms 1336 KB Output is correct
28 Correct 112 ms 26556 KB Output is correct
29 Correct 165 ms 38256 KB Output is correct
30 Correct 237 ms 53236 KB Output is correct
31 Correct 307 ms 62664 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 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 348 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 104 ms 26484 KB Output is correct
46 Correct 168 ms 39808 KB Output is correct
47 Correct 170 ms 39656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 98 ms 27348 KB Output is correct
10 Correct 8 ms 3160 KB Output is correct
11 Correct 48 ms 14972 KB Output is correct
12 Correct 13 ms 4700 KB Output is correct
13 Correct 32 ms 10276 KB Output is correct
14 Correct 1 ms 652 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 104 ms 25972 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 384 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 348 KB Output is correct
23 Correct 299 ms 63180 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 3 ms 1336 KB Output is correct
28 Correct 112 ms 26556 KB Output is correct
29 Correct 165 ms 38256 KB Output is correct
30 Correct 237 ms 53236 KB Output is correct
31 Correct 307 ms 62664 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 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 348 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 104 ms 26484 KB Output is correct
46 Correct 168 ms 39808 KB Output is correct
47 Correct 170 ms 39656 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 436 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 440 KB Output is correct
55 Correct 295 ms 59176 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 1116 KB Output is correct
58 Correct 6 ms 2380 KB Output is correct
59 Correct 8 ms 2652 KB Output is correct
60 Correct 127 ms 31136 KB Output is correct
61 Correct 185 ms 42116 KB Output is correct
62 Correct 239 ms 50588 KB Output is correct
63 Correct 305 ms 60408 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 234 ms 54800 KB Output is correct
68 Correct 235 ms 54804 KB Output is correct
69 Correct 231 ms 55440 KB Output is correct
70 Correct 3 ms 1232 KB Output is correct
71 Correct 6 ms 2140 KB Output is correct
72 Correct 100 ms 26100 KB Output is correct
73 Correct 179 ms 40592 KB Output is correct
74 Correct 243 ms 52612 KB Output is correct
75 Correct 264 ms 59776 KB Output is correct
76 Correct 233 ms 56708 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 7 ms 2396 KB Output is correct
79 Correct 122 ms 27576 KB Output is correct
80 Correct 172 ms 41868 KB Output is correct
81 Correct 251 ms 56712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 98 ms 27348 KB Output is correct
10 Correct 8 ms 3160 KB Output is correct
11 Correct 48 ms 14972 KB Output is correct
12 Correct 13 ms 4700 KB Output is correct
13 Correct 32 ms 10276 KB Output is correct
14 Correct 1 ms 652 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 104 ms 25972 KB Output is correct
17 Correct 1 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 256 ms 55720 KB Output is correct
21 Correct 241 ms 56608 KB Output is correct
22 Correct 261 ms 55940 KB Output is correct
23 Correct 194 ms 46936 KB Output is correct
24 Correct 116 ms 24524 KB Output is correct
25 Correct 204 ms 42956 KB Output is correct
26 Correct 195 ms 42952 KB Output is correct
27 Correct 236 ms 50320 KB Output is correct
28 Correct 232 ms 50308 KB Output is correct
29 Correct 250 ms 50312 KB Output is correct
30 Correct 240 ms 50316 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Incorrect 11 ms 3548 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 98 ms 27348 KB Output is correct
10 Correct 8 ms 3160 KB Output is correct
11 Correct 48 ms 14972 KB Output is correct
12 Correct 13 ms 4700 KB Output is correct
13 Correct 32 ms 10276 KB Output is correct
14 Correct 1 ms 652 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 104 ms 25972 KB Output is correct
17 Correct 242 ms 55428 KB Output is correct
18 Correct 244 ms 55020 KB Output is correct
19 Correct 244 ms 53896 KB Output is correct
20 Correct 276 ms 60420 KB Output is correct
21 Correct 211 ms 49408 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Incorrect 33 ms 7376 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 98 ms 27348 KB Output is correct
10 Correct 8 ms 3160 KB Output is correct
11 Correct 48 ms 14972 KB Output is correct
12 Correct 13 ms 4700 KB Output is correct
13 Correct 32 ms 10276 KB Output is correct
14 Correct 1 ms 652 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 104 ms 25972 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 384 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 348 KB Output is correct
23 Correct 299 ms 63180 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 2 ms 1116 KB Output is correct
27 Correct 3 ms 1336 KB Output is correct
28 Correct 112 ms 26556 KB Output is correct
29 Correct 165 ms 38256 KB Output is correct
30 Correct 237 ms 53236 KB Output is correct
31 Correct 307 ms 62664 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 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 348 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 104 ms 26484 KB Output is correct
46 Correct 168 ms 39808 KB Output is correct
47 Correct 170 ms 39656 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 436 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 440 KB Output is correct
55 Correct 295 ms 59176 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 2 ms 1116 KB Output is correct
58 Correct 6 ms 2380 KB Output is correct
59 Correct 8 ms 2652 KB Output is correct
60 Correct 127 ms 31136 KB Output is correct
61 Correct 185 ms 42116 KB Output is correct
62 Correct 239 ms 50588 KB Output is correct
63 Correct 305 ms 60408 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 234 ms 54800 KB Output is correct
68 Correct 235 ms 54804 KB Output is correct
69 Correct 231 ms 55440 KB Output is correct
70 Correct 3 ms 1232 KB Output is correct
71 Correct 6 ms 2140 KB Output is correct
72 Correct 100 ms 26100 KB Output is correct
73 Correct 179 ms 40592 KB Output is correct
74 Correct 243 ms 52612 KB Output is correct
75 Correct 264 ms 59776 KB Output is correct
76 Correct 233 ms 56708 KB Output is correct
77 Correct 4 ms 1368 KB Output is correct
78 Correct 7 ms 2396 KB Output is correct
79 Correct 122 ms 27576 KB Output is correct
80 Correct 172 ms 41868 KB Output is correct
81 Correct 251 ms 56712 KB Output is correct
82 Correct 1 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 256 ms 55720 KB Output is correct
86 Correct 241 ms 56608 KB Output is correct
87 Correct 261 ms 55940 KB Output is correct
88 Correct 194 ms 46936 KB Output is correct
89 Correct 116 ms 24524 KB Output is correct
90 Correct 204 ms 42956 KB Output is correct
91 Correct 195 ms 42952 KB Output is correct
92 Correct 236 ms 50320 KB Output is correct
93 Correct 232 ms 50308 KB Output is correct
94 Correct 250 ms 50312 KB Output is correct
95 Correct 240 ms 50316 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Incorrect 11 ms 3548 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -