답안 #1063124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063124 2024-08-17T14:26:51 Z fv3 분수 공원 (IOI21_parks) C++17
5 / 100
120 ms 36764 KB
#include "parks.h"
#include <bits/stdc++.h>

using namespace std;
vector<vector<int>> adj;
vector<int> visited;

int DFS(int index)
{
    int sz = 1;
    visited[index] = 1;
    for (auto node : adj[index])
    {
        if (visited[node]) continue;
        sz += DFS(node);
    }
    return sz;
}

int construct_roads(vector<int> x, vector<int> y) 
{
    if (x.size() == 1) 
    {
        build({}, {}, {}, {});
        return 1;
    }

    // x[i] = 2
    const int N = x.size();

    vector<pair<int, int>> l = {}, r = {};
    for (int i = 0; i < N; i++)
    {
        if (x[i] == 2)
            l.push_back({y[i], i});
        else
            r.push_back({y[i], i});
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());

    adj = vector<vector<int>>(N);
    vector<int> U, V, A, B;
    for (int i = 0; i < (int)l.size() - 1; i++)
    {
        if (l[i].first + 2 != l[i+1].first) continue;
        int a = l[i].second;
        int b = l[i+1].second;

        adj[a].push_back(b);
        adj[b].push_back(a);

        U.push_back(a); 
        V.push_back(b);
        A.push_back(1); 
        B.push_back(l[i].first + 1);
    }
    for (int i = 0; i < (int)r.size() - 1; i++)
    {
        if (r[i].first + 2 != r[i+1].first) continue;
        int a = r[i].second;
        int b = r[i+1].second;

        adj[a].push_back(b);
        adj[b].push_back(a);

        U.push_back(a); 
        V.push_back(b);
        A.push_back(5); 
        B.push_back(r[i].first + 1);
    }


    if (r.size())
        l.insert(l.end(), r.begin(), r.end());
    sort(l.begin(), l.end());    
    for (int i = 0; i < N - 1; i++)
    {
        if (l[i].first != l[i+1].first) continue;
        int a = l[i].second;
        int b = l[i+1].second;

        adj[a].push_back(b);
        adj[b].push_back(a);

        U.push_back(a); 
        V.push_back(b);
        A.push_back(l[i].first + 1); 
        B.push_back(3);
    }

    visited = vector<int>(N);
    int sz = DFS(0);
    if (sz != N) return 0;

    build(U, V, A, B);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 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 432 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 24 ms 9604 KB Output is correct
12 Correct 6 ms 3044 KB Output is correct
13 Correct 10 ms 6100 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 60 ms 16392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 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 432 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 24 ms 9604 KB Output is correct
12 Correct 6 ms 3044 KB Output is correct
13 Correct 10 ms 6100 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 60 ms 16392 KB Output is correct
17 Incorrect 0 ms 348 KB Tree (a[3], b[3]) = (5, 3) is not adjacent to edge between u[3]=0 @(4, 4) and v[3]=1 @(2, 4)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 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 432 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 24 ms 9604 KB Output is correct
12 Correct 6 ms 3044 KB Output is correct
13 Correct 10 ms 6100 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 60 ms 16392 KB Output is correct
17 Incorrect 0 ms 348 KB Tree (a[3], b[3]) = (5, 3) is not adjacent to edge between u[3]=0 @(4, 4) and v[3]=1 @(2, 4)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 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 432 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 24 ms 9604 KB Output is correct
12 Correct 6 ms 3044 KB Output is correct
13 Correct 10 ms 6100 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 60 ms 16392 KB Output is correct
17 Incorrect 0 ms 344 KB Pair u[0]=2 @(199998, 2) and v[0]=1 @(200000, 4) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 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 432 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 24 ms 9604 KB Output is correct
12 Correct 6 ms 3044 KB Output is correct
13 Correct 10 ms 6100 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 60 ms 16392 KB Output is correct
17 Incorrect 120 ms 36764 KB Pair u[50000]=199999 @(62538, 2) and v[50000]=87394 @(100002, 4) does not form a valid edge (distance != 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 356 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 432 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 52 ms 17632 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 24 ms 9604 KB Output is correct
12 Correct 6 ms 3044 KB Output is correct
13 Correct 10 ms 6100 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 60 ms 16392 KB Output is correct
17 Incorrect 0 ms 348 KB Tree (a[3], b[3]) = (5, 3) is not adjacent to edge between u[3]=0 @(4, 4) and v[3]=1 @(2, 4)
18 Halted 0 ms 0 KB -