답안 #1050876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050876 2024-08-09T15:59:14 Z amine_aroua 분수 공원 (IOI21_parks) C++17
30 / 100
3500 ms 63136 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)
        {
            shuffle(vv.begin() , vv.end() , rng);
            continue;
            
        }
        build(u , v , a , b);
        return 1;
    }
    return 0;
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 114 ms 27228 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 49 ms 14988 KB Output is correct
12 Correct 12 ms 4700 KB Output is correct
13 Correct 675 ms 10344 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 16 ms 864 KB Output is correct
16 Correct 103 ms 25920 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 114 ms 27228 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 49 ms 14988 KB Output is correct
12 Correct 12 ms 4700 KB Output is correct
13 Correct 675 ms 10344 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 16 ms 864 KB Output is correct
16 Correct 103 ms 25920 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 348 KB Output is correct
23 Correct 359 ms 63136 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 812 KB Output is correct
26 Correct 35 ms 1116 KB Output is correct
27 Correct 50 ms 1368 KB Output is correct
28 Correct 118 ms 26596 KB Output is correct
29 Correct 174 ms 38348 KB Output is correct
30 Correct 259 ms 53236 KB Output is correct
31 Correct 312 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 348 KB Output is correct
43 Correct 16 ms 876 KB Output is correct
44 Correct 26 ms 860 KB Output is correct
45 Correct 109 ms 26280 KB Output is correct
46 Correct 171 ms 38632 KB Output is correct
47 Correct 167 ms 38380 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 114 ms 27228 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 49 ms 14988 KB Output is correct
12 Correct 12 ms 4700 KB Output is correct
13 Correct 675 ms 10344 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 16 ms 864 KB Output is correct
16 Correct 103 ms 25920 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 348 KB Output is correct
23 Correct 359 ms 63136 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 812 KB Output is correct
26 Correct 35 ms 1116 KB Output is correct
27 Correct 50 ms 1368 KB Output is correct
28 Correct 118 ms 26596 KB Output is correct
29 Correct 174 ms 38348 KB Output is correct
30 Correct 259 ms 53236 KB Output is correct
31 Correct 312 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 348 KB Output is correct
43 Correct 16 ms 876 KB Output is correct
44 Correct 26 ms 860 KB Output is correct
45 Correct 109 ms 26280 KB Output is correct
46 Correct 171 ms 38632 KB Output is correct
47 Correct 167 ms 38380 KB Output is correct
48 Correct 0 ms 348 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 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 334 ms 57664 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 160 ms 2652 KB Output is correct
60 Correct 164 ms 30404 KB Output is correct
61 Correct 200 ms 41220 KB Output is correct
62 Correct 273 ms 49312 KB Output is correct
63 Correct 331 ms 58844 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 253 ms 53260 KB Output is correct
68 Correct 263 ms 53252 KB Output is correct
69 Correct 281 ms 53820 KB Output is correct
70 Correct 37 ms 1116 KB Output is correct
71 Correct 92 ms 1884 KB Output is correct
72 Correct 104 ms 25256 KB Output is correct
73 Correct 174 ms 39120 KB Output is correct
74 Correct 253 ms 50960 KB Output is correct
75 Correct 270 ms 58220 KB Output is correct
76 Correct 245 ms 55056 KB Output is correct
77 Correct 53 ms 1372 KB Output is correct
78 Correct 112 ms 2396 KB Output is correct
79 Correct 106 ms 26792 KB Output is correct
80 Correct 175 ms 40596 KB Output is correct
81 Correct 255 ms 54660 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 114 ms 27228 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 49 ms 14988 KB Output is correct
12 Correct 12 ms 4700 KB Output is correct
13 Correct 675 ms 10344 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 16 ms 864 KB Output is correct
16 Correct 103 ms 25920 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 244 ms 55688 KB Output is correct
21 Correct 250 ms 54352 KB Output is correct
22 Correct 250 ms 53640 KB Output is correct
23 Correct 198 ms 45200 KB Output is correct
24 Correct 1410 ms 22988 KB Output is correct
25 Execution timed out 3588 ms 41160 KB Time limit exceeded
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 114 ms 27228 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 49 ms 14988 KB Output is correct
12 Correct 12 ms 4700 KB Output is correct
13 Correct 675 ms 10344 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 16 ms 864 KB Output is correct
16 Correct 103 ms 25920 KB Output is correct
17 Correct 240 ms 55440 KB Output is correct
18 Correct 242 ms 54916 KB Output is correct
19 Correct 268 ms 54032 KB Output is correct
20 Correct 275 ms 58904 KB Output is correct
21 Correct 206 ms 48128 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Incorrect 536 ms 7160 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 114 ms 27228 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 49 ms 14988 KB Output is correct
12 Correct 12 ms 4700 KB Output is correct
13 Correct 675 ms 10344 KB Output is correct
14 Correct 7 ms 604 KB Output is correct
15 Correct 16 ms 864 KB Output is correct
16 Correct 103 ms 25920 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 348 KB Output is correct
23 Correct 359 ms 63136 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 812 KB Output is correct
26 Correct 35 ms 1116 KB Output is correct
27 Correct 50 ms 1368 KB Output is correct
28 Correct 118 ms 26596 KB Output is correct
29 Correct 174 ms 38348 KB Output is correct
30 Correct 259 ms 53236 KB Output is correct
31 Correct 312 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 348 KB Output is correct
43 Correct 16 ms 876 KB Output is correct
44 Correct 26 ms 860 KB Output is correct
45 Correct 109 ms 26280 KB Output is correct
46 Correct 171 ms 38632 KB Output is correct
47 Correct 167 ms 38380 KB Output is correct
48 Correct 0 ms 348 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 348 KB Output is correct
53 Correct 1 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 334 ms 57664 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 160 ms 2652 KB Output is correct
60 Correct 164 ms 30404 KB Output is correct
61 Correct 200 ms 41220 KB Output is correct
62 Correct 273 ms 49312 KB Output is correct
63 Correct 331 ms 58844 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 253 ms 53260 KB Output is correct
68 Correct 263 ms 53252 KB Output is correct
69 Correct 281 ms 53820 KB Output is correct
70 Correct 37 ms 1116 KB Output is correct
71 Correct 92 ms 1884 KB Output is correct
72 Correct 104 ms 25256 KB Output is correct
73 Correct 174 ms 39120 KB Output is correct
74 Correct 253 ms 50960 KB Output is correct
75 Correct 270 ms 58220 KB Output is correct
76 Correct 245 ms 55056 KB Output is correct
77 Correct 53 ms 1372 KB Output is correct
78 Correct 112 ms 2396 KB Output is correct
79 Correct 106 ms 26792 KB Output is correct
80 Correct 175 ms 40596 KB Output is correct
81 Correct 255 ms 54660 KB Output is correct
82 Correct 0 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 244 ms 55688 KB Output is correct
86 Correct 250 ms 54352 KB Output is correct
87 Correct 250 ms 53640 KB Output is correct
88 Correct 198 ms 45200 KB Output is correct
89 Correct 1410 ms 22988 KB Output is correct
90 Execution timed out 3588 ms 41160 KB Time limit exceeded
91 Halted 0 ms 0 KB -