답안 #578301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578301 2022-06-16T10:41:01 Z johnf 게임 (APIO22_game) C++17
60 / 100
1098 ms 28008 KB
#include "game.h"
#include <bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;
using vi = vector<int>;

template <class T>
bool uin(T &a, T b) {
    return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n, k;

namespace sub3 {
vector<vi> adj;
stack<int> st;
int id = 0;
vi low, num;

bool eligible() { return n <= 1000; }

void init() {
    adj.assign(n, {});
    fore(i, 0, k - 2) { adj[i].pb(i + 1); }
}

bool dfs(int u) {
    low[u] = num[u] = ++id;
    st.push(u);
    for (auto v : adj[u]) {
        if (num[v]) {
            uin(low[u], num[v]);
        } else {
            if (dfs(v)) {
                return 1;
            }
            uin(low[u], low[v]);
        }
    }
    if (low[u] == num[u]) {
        int v;
        vector<int> vec;
        do {
            v = st.top();
            st.pop();
            low[v] = num[v] = 1e9;
            vec.pb(v);
        } while (v != u);
        if (vec.size() >= 2) {
            for (auto x : vec) {
                if (x < k) {
                    return 1;
                }
            }
        }
    }
    return 0;
}

int add_teleporter(int u, int v) {
    if (u == v) {
        if (u < k) {
            return 1;
        }
    } else {
        adj[u].pb(v);
    }
    low = num = vi(n);
    id = 0;
    for0(i, n) {
        if (!num[i]) {
            if (dfs(i)) {
                return 1;
            }
        }
    }
    return 0;
}
}

namespace sub4 {
vector<vi> adj, adj_rev;
vector<int> min_reach, max_reach;

bool eligible() { return k <= 1000; }

void init() {
    adj.assign(n, {});
    adj_rev.assign(n, {});
    min_reach.assign(n, k);
    max_reach.assign(n, -1);
}

int add_teleporter(int u, int v) {
    if (u < k && v < k) {
        if (u >= v) {
            return 1;
        }
        return 0;
    }
    adj[u].pb(v);
    adj_rev[v].pb(u);
    queue<int> q;
    if (v < k) {
        if (uin(min_reach[u], v)) {
            q.push(u);
        }
    } else if (uin(min_reach[u], min_reach[v])) {
        q.push(u);
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (min_reach[u] <= max_reach[u]) {
            return 1;
        }
        for (auto v : adj_rev[u]) {
            if (uin(min_reach[v], min_reach[u])) {
                q.push(v);
            }
        }
    }
    if (u < k) {
        if (uax(max_reach[v], u)) {
            q.push(v);
        }
    } else if (uax(max_reach[v], max_reach[u])) {
        q.push(v);
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (min_reach[u] <= max_reach[u]) {
            return 1;
        }
        for (auto v : adj[u]) {
            if (uax(max_reach[v], max_reach[u])) {
                q.push(v);
            }
        }
    }
    return 0;
}
};

void init(int N, int K) {
    n = N;
    k = K;
    if (sub3::eligible()) {
        sub3::init();
    } else if (sub4::eligible()) {
        sub4::init();
    }
}

int add_teleporter(int u, int v) {
    if (sub3::eligible()) {
        return sub3::add_teleporter(u, v);
    } else if (sub4::eligible()) {
        return sub4::add_teleporter(u, v);
    }
}

Compilation message

game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:188:1: warning: control reaches end of non-void function [-Wreturn-type]
  188 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 48 ms 336 KB Output is correct
21 Correct 6 ms 336 KB Output is correct
22 Correct 45 ms 364 KB Output is correct
23 Correct 61 ms 348 KB Output is correct
24 Correct 49 ms 336 KB Output is correct
25 Correct 227 ms 412 KB Output is correct
26 Correct 271 ms 476 KB Output is correct
27 Correct 224 ms 412 KB Output is correct
28 Correct 111 ms 400 KB Output is correct
29 Correct 203 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 48 ms 336 KB Output is correct
21 Correct 6 ms 336 KB Output is correct
22 Correct 45 ms 364 KB Output is correct
23 Correct 61 ms 348 KB Output is correct
24 Correct 49 ms 336 KB Output is correct
25 Correct 227 ms 412 KB Output is correct
26 Correct 271 ms 476 KB Output is correct
27 Correct 224 ms 412 KB Output is correct
28 Correct 111 ms 400 KB Output is correct
29 Correct 203 ms 520 KB Output is correct
30 Correct 16 ms 3136 KB Output is correct
31 Correct 5 ms 2256 KB Output is correct
32 Correct 20 ms 3772 KB Output is correct
33 Correct 20 ms 3704 KB Output is correct
34 Correct 1098 ms 4016 KB Output is correct
35 Correct 399 ms 3916 KB Output is correct
36 Correct 40 ms 3704 KB Output is correct
37 Correct 36 ms 3752 KB Output is correct
38 Correct 43 ms 3532 KB Output is correct
39 Correct 35 ms 3528 KB Output is correct
40 Correct 933 ms 4100 KB Output is correct
41 Correct 194 ms 3600 KB Output is correct
42 Correct 133 ms 3532 KB Output is correct
43 Correct 49 ms 3912 KB Output is correct
44 Correct 716 ms 3904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 48 ms 336 KB Output is correct
21 Correct 6 ms 336 KB Output is correct
22 Correct 45 ms 364 KB Output is correct
23 Correct 61 ms 348 KB Output is correct
24 Correct 49 ms 336 KB Output is correct
25 Correct 227 ms 412 KB Output is correct
26 Correct 271 ms 476 KB Output is correct
27 Correct 224 ms 412 KB Output is correct
28 Correct 111 ms 400 KB Output is correct
29 Correct 203 ms 520 KB Output is correct
30 Correct 16 ms 3136 KB Output is correct
31 Correct 5 ms 2256 KB Output is correct
32 Correct 20 ms 3772 KB Output is correct
33 Correct 20 ms 3704 KB Output is correct
34 Correct 1098 ms 4016 KB Output is correct
35 Correct 399 ms 3916 KB Output is correct
36 Correct 40 ms 3704 KB Output is correct
37 Correct 36 ms 3752 KB Output is correct
38 Correct 43 ms 3532 KB Output is correct
39 Correct 35 ms 3528 KB Output is correct
40 Correct 933 ms 4100 KB Output is correct
41 Correct 194 ms 3600 KB Output is correct
42 Correct 133 ms 3532 KB Output is correct
43 Correct 49 ms 3912 KB Output is correct
44 Correct 716 ms 3904 KB Output is correct
45 Correct 313 ms 28008 KB Output is correct
46 Correct 17 ms 17104 KB Output is correct
47 Runtime error 1 ms 336 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -