답안 #1064544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064544 2024-08-18T14:15:03 Z c2zi6 분수 공원 (IOI21_parks) C++17
15 / 100
551 ms 115412 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "parks.h"

int n;
VVI gp;
VPI cord;

VPI bench(int u, int v) {
    int dir = -1;
    if (gp[u][0] == v) dir = 0;
    else if (gp[u][1] == v) dir = 1;
    else if (gp[u][2] == v) dir = 2;
    else if (gp[u][3] == v) dir = 3;
    assert(dir != -1);
    int x, y;
    tie(x, y) = cord[u];
    if (dir == 0) return {{x-1, y-1}, {x-1, y+1}};
    if (dir == 1) return {{x-1, y+1}, {x+1, y+1}};
    if (dir == 2) return {{x+1, y+1}, {x+1, y-1}};
    if (dir == 3) return {{x+1, y-1}, {x-1, y-1}};
    return {};
}

VPI edges;
VI vis;
void dfs(int u) {
    vis[u] = 1;
    for (int v : gp[u]) if (v != -1) {
        if (vis[v] == 1) {
            /* (u, v) is a back-edge */
        } else if (vis[v] == 0) {
            /* (u, v) is a span-edge */
            edges.pb({u, v});
            dfs(v);
        }
    }
    vis[u] = 2;
}

void dfs(VVI& gp, int u) {
    vis[u] = 1;
    for (int v : gp[u]) if (v != -1) {
        if (vis[v] == 1) {
        } else if (vis[v] == 0) {
            edges.pb({u, v});
            dfs(v);
        }
    }
    vis[u] = 2;
}

void build(VPI edges, VPI benches) {
    int m = edges.size();
    VI ret[4];
    rep(i, m) ret[0].pb(edges[i].ff);
    rep(i, m) ret[1].pb(edges[i].ss);
    rep(i, m) ret[2].pb(benches[i].ff);
    rep(i, m) ret[3].pb(benches[i].ss);
    build(ret[0], ret[1], ret[2], ret[3]);
}

int construct_roads(VI x_arg, VI y_arg) {
    if (true) {
        n = x_arg.size();
        cord = VPI(n);
        rep(i, n) cord[i] = {x_arg[i], y_arg[i]};
        gp = VVI(n);
        map<PII, int> mp;
        rep(i, n) mp[{x_arg[i], y_arg[i]}] = i;
        rep(u, n) {
            int x = x_arg[u];
            int y = y_arg[u];
            if (mp.count({x-2, y})) {
                gp[u].pb(mp[{x-2, y}]);
            } else gp[u].pb(-1);
            if (mp.count({x, y+2})) {
                gp[u].pb(mp[{x, y+2}]);
            } else gp[u].pb(-1);
            if (mp.count({x+2, y})) {
                gp[u].pb(mp[{x+2, y}]);
            } else gp[u].pb(-1);
            if (mp.count({x, y-2})) {
                gp[u].pb(mp[{x, y-2}]);
            } else gp[u].pb(-1);
        }
    }
    vis = VI(n);
    queue<int> q;
    q.push(0);
    vis[0] = true;
    while (q.size()) {
        int u = q.front();
        q.pop();
        for (int v : gp[u]) if (v != -1) {
            if (vis[v]) continue;
            edges.pb({u, v});
            vis[v] = true;
            q.push(v);
        }
    }
    for (int x : vis) if (x == 0) return 0;

    VVI gpb(n);
    for (auto[u, v] : edges) {
        gpb[u].pb(v);
        gpb[v].pb(u);
    }
    edges = VPI();
    vis = VI(n);
    dfs(gpb, 0);

    /*cout << "EDGES: " << endl;*/
    /*for (auto[u, v] : edges) cout << u << " " << v << endl;*/

    VPI benches;
    set<PII> st;
    for (auto[u, v] : edges) {
        bool good = false;
        for (auto[x, y] : bench(u, v)) {
            if (st.count({x, y})) continue;
            good = true;
            benches.pb({x, y});
            st.insert({x, y});
            break;
        }
        assert(good);
    }
    build(edges, benches);
    return 1;
}








# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 185 ms 34860 KB Output is correct
10 Correct 11 ms 4068 KB Output is correct
11 Correct 71 ms 19204 KB Output is correct
12 Correct 20 ms 5604 KB Output is correct
13 Correct 33 ms 6992 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 176 ms 31416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 185 ms 34860 KB Output is correct
10 Correct 11 ms 4068 KB Output is correct
11 Correct 71 ms 19204 KB Output is correct
12 Correct 20 ms 5604 KB Output is correct
13 Correct 33 ms 6992 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 176 ms 31416 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 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 503 ms 68608 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 166 ms 28748 KB Output is correct
29 Correct 294 ms 42420 KB Output is correct
30 Correct 394 ms 56584 KB Output is correct
31 Correct 542 ms 67152 KB Output is correct
32 Correct 1 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 344 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 1 ms 348 KB Output is correct
41 Correct 0 ms 436 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 692 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 267 ms 32512 KB Output is correct
46 Correct 308 ms 47640 KB Output is correct
47 Correct 353 ms 47084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 185 ms 34860 KB Output is correct
10 Correct 11 ms 4068 KB Output is correct
11 Correct 71 ms 19204 KB Output is correct
12 Correct 20 ms 5604 KB Output is correct
13 Correct 33 ms 6992 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 176 ms 31416 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 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 503 ms 68608 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 166 ms 28748 KB Output is correct
29 Correct 294 ms 42420 KB Output is correct
30 Correct 394 ms 56584 KB Output is correct
31 Correct 542 ms 67152 KB Output is correct
32 Correct 1 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 344 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 1 ms 348 KB Output is correct
41 Correct 0 ms 436 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 692 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 267 ms 32512 KB Output is correct
46 Correct 308 ms 47640 KB Output is correct
47 Correct 353 ms 47084 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 604 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 551 ms 66304 KB Output is correct
56 Runtime error 1 ms 344 KB Execution killed with signal 6
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 185 ms 34860 KB Output is correct
10 Correct 11 ms 4068 KB Output is correct
11 Correct 71 ms 19204 KB Output is correct
12 Correct 20 ms 5604 KB Output is correct
13 Correct 33 ms 6992 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 176 ms 31416 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 388 KB Output is correct
20 Correct 477 ms 71248 KB Output is correct
21 Correct 466 ms 68160 KB Output is correct
22 Correct 458 ms 66372 KB Output is correct
23 Correct 359 ms 55316 KB Output is correct
24 Correct 253 ms 30292 KB Output is correct
25 Correct 369 ms 30036 KB Output is correct
26 Correct 329 ms 30036 KB Output is correct
27 Correct 484 ms 55240 KB Output is correct
28 Runtime error 416 ms 65092 KB Execution killed with signal 6
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 185 ms 34860 KB Output is correct
10 Correct 11 ms 4068 KB Output is correct
11 Correct 71 ms 19204 KB Output is correct
12 Correct 20 ms 5604 KB Output is correct
13 Correct 33 ms 6992 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 176 ms 31416 KB Output is correct
17 Correct 426 ms 71300 KB Output is correct
18 Correct 432 ms 69712 KB Output is correct
19 Runtime error 462 ms 115412 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 185 ms 34860 KB Output is correct
10 Correct 11 ms 4068 KB Output is correct
11 Correct 71 ms 19204 KB Output is correct
12 Correct 20 ms 5604 KB Output is correct
13 Correct 33 ms 6992 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 176 ms 31416 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 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 503 ms 68608 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 166 ms 28748 KB Output is correct
29 Correct 294 ms 42420 KB Output is correct
30 Correct 394 ms 56584 KB Output is correct
31 Correct 542 ms 67152 KB Output is correct
32 Correct 1 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 344 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 1 ms 348 KB Output is correct
41 Correct 0 ms 436 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 692 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 267 ms 32512 KB Output is correct
46 Correct 308 ms 47640 KB Output is correct
47 Correct 353 ms 47084 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 604 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 551 ms 66304 KB Output is correct
56 Runtime error 1 ms 344 KB Execution killed with signal 6
57 Halted 0 ms 0 KB -