답안 #1050866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050866 2024-08-09T15:47:42 Z amine_aroua 분수 공원 (IOI21_parks) C++17
5 / 100
507 ms 58636 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]});
    int cnt = 1;
    while(cnt--)
    {
        u.clear();
        v.clear();
        a.clear();
        b.clear();
        taken.clear();
        adj.assign(n , {});
        vis.assign(n ,0);
        shuffle(vv.begin() , vv.end() , rng);
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 138 ms 27320 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 68 ms 14952 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 48 ms 10448 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 145 ms 26032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 138 ms 27320 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 68 ms 14952 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 48 ms 10448 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 145 ms 26032 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 454 ms 58636 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 3 ms 948 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 147 ms 23816 KB Output is correct
29 Correct 247 ms 34068 KB Output is correct
30 Correct 348 ms 47388 KB Output is correct
31 Correct 507 ms 58444 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 428 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 2 ms 604 KB Output is correct
44 Correct 2 ms 968 KB Output is correct
45 Incorrect 142 ms 22476 KB Solution announced impossible, but it is possible.
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 138 ms 27320 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 68 ms 14952 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 48 ms 10448 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 145 ms 26032 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 454 ms 58636 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 3 ms 948 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 147 ms 23816 KB Output is correct
29 Correct 247 ms 34068 KB Output is correct
30 Correct 348 ms 47388 KB Output is correct
31 Correct 507 ms 58444 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 428 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 2 ms 604 KB Output is correct
44 Correct 2 ms 968 KB Output is correct
45 Incorrect 142 ms 22476 KB Solution announced impossible, but it is possible.
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 138 ms 27320 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 68 ms 14952 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 48 ms 10448 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 145 ms 26032 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 Incorrect 286 ms 39228 KB Solution announced impossible, but it is possible.
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 138 ms 27320 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 68 ms 14952 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 48 ms 10448 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 145 ms 26032 KB Output is correct
17 Correct 355 ms 55432 KB Output is correct
18 Correct 356 ms 54924 KB Output is correct
19 Incorrect 320 ms 41928 KB Solution announced impossible, but it is possible.
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 138 ms 27320 KB Output is correct
10 Correct 10 ms 3160 KB Output is correct
11 Correct 68 ms 14952 KB Output is correct
12 Correct 16 ms 4700 KB Output is correct
13 Correct 48 ms 10448 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 145 ms 26032 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 454 ms 58636 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 3 ms 948 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 147 ms 23816 KB Output is correct
29 Correct 247 ms 34068 KB Output is correct
30 Correct 348 ms 47388 KB Output is correct
31 Correct 507 ms 58444 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 428 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 2 ms 604 KB Output is correct
44 Correct 2 ms 968 KB Output is correct
45 Incorrect 142 ms 22476 KB Solution announced impossible, but it is possible.
46 Halted 0 ms 0 KB -