답안 #1064536

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064536 2024-08-18T14:09:48 Z c2zi6 분수 공원 (IOI21_parks) C++17
0 / 100
0 ms 348 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 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);
    /*dfs(0);*/
    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;

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

    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 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Tree (a[0], b[0]) = (1, 1) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(2, 4)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Tree (a[0], b[0]) = (1, 1) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(2, 4)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Tree (a[0], b[0]) = (1, 1) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(2, 4)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Tree (a[0], b[0]) = (1, 1) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(2, 4)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Tree (a[0], b[0]) = (1, 1) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(2, 4)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Tree (a[0], b[0]) = (1, 1) is not adjacent to edge between u[0]=0 @(2, 2) and v[0]=1 @(2, 4)
3 Halted 0 ms 0 KB -