Submission #948811

# Submission time Handle Problem Language Result Execution time Memory
948811 2024-03-18T14:42:01 Z Nhoksocqt1 Game (APIO22_game) C++17
30 / 100
4000 ms 13600 KB
#ifndef Nhoksocqt1
    #include "game.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 300005;
const int MAXM = 600005;

vector<ii> adj[MAXN];
int low[MAXN], num[MAXN], numNode, numEdge, numSpecial;
bool dxe[MAXM];

void init(int _N, int _K) {
    numNode = _N, numSpecial = _K;
    for (int i = 0; i + 1 < numSpecial; ++i)
        adj[i].push_back(ii(i + 1, i));

    numEdge = numSpecial - 1;
}

stack<int> st;
bool tarjan(int u) {
    low[u] = num[u] = ++num[numNode];
    st.push(u);

    for (int it = 0; it < sz(adj[u]); ++it) {
        int v(adj[u][it].fi), id(adj[u][it].se);
        if(!dxe[id]) {
            dxe[id] = 1;
            if(!num[v]) {
                if(tarjan(v))
                    return true;

                low[u] = min(low[u], low[v]);
            } else {
                low[u] = min(low[u], num[v]);
            }
        }
    }

    if(low[u] == num[u]) {
        int v, cnt(0);
        bool has_special(0);
        do {
            v = st.top(); st.pop();
            low[v] = num[v] = 1e9+7;
            has_special |= (v < numSpecial), ++cnt;
        } while(v != u);

        return (cnt > 1 && has_special);
    }

    return false;
}

int add_teleporter(int u, int v) {
    if(u == v && u < numSpecial)
        return 1;

    adj[u].push_back(ii(v, numEdge++));
    for (int i = 0; i <= numNode; ++i)
        low[i] = num[i] = 0;

    while(sz(st))
        st.pop();

    for (int i = 0; i < numEdge; ++i)
        dxe[i] = 0;

    for (int i = 0; i < numSpecial; ++i) {
        if(!num[i] && tarjan(i))
            return 1;
    }

    return 0;
}

#ifdef Nhoksocqt1

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #define TASK "game"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    int n, k, m;
    cin >> n >> k >> m;

    init(n, k);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        int ans = add_teleporter(u, v);
        cout << "ANSWER FOR EDGE " << u << " TO " << v << ": " << ans << '\n';
    }

    return 0;
}

#endif // Nhoksocqt1
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 3 ms 10072 KB Output is correct
5 Correct 3 ms 10072 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 3 ms 10072 KB Output is correct
5 Correct 3 ms 10072 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 2 ms 10072 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 10072 KB Output is correct
12 Correct 2 ms 10172 KB Output is correct
13 Correct 4 ms 10072 KB Output is correct
14 Correct 3 ms 10072 KB Output is correct
15 Correct 3 ms 10320 KB Output is correct
16 Correct 3 ms 10072 KB Output is correct
17 Correct 3 ms 10072 KB Output is correct
18 Correct 2 ms 10172 KB Output is correct
19 Correct 3 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 3 ms 10072 KB Output is correct
5 Correct 3 ms 10072 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 2 ms 10072 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 10072 KB Output is correct
12 Correct 2 ms 10172 KB Output is correct
13 Correct 4 ms 10072 KB Output is correct
14 Correct 3 ms 10072 KB Output is correct
15 Correct 3 ms 10320 KB Output is correct
16 Correct 3 ms 10072 KB Output is correct
17 Correct 3 ms 10072 KB Output is correct
18 Correct 2 ms 10172 KB Output is correct
19 Correct 3 ms 10072 KB Output is correct
20 Correct 3 ms 10072 KB Output is correct
21 Correct 3 ms 10072 KB Output is correct
22 Correct 4 ms 10328 KB Output is correct
23 Correct 3 ms 10072 KB Output is correct
24 Correct 13 ms 10432 KB Output is correct
25 Correct 40 ms 10328 KB Output is correct
26 Correct 54 ms 10328 KB Output is correct
27 Correct 62 ms 10656 KB Output is correct
28 Correct 23 ms 10328 KB Output is correct
29 Correct 46 ms 10348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 3 ms 10072 KB Output is correct
5 Correct 3 ms 10072 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 2 ms 10072 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 10072 KB Output is correct
12 Correct 2 ms 10172 KB Output is correct
13 Correct 4 ms 10072 KB Output is correct
14 Correct 3 ms 10072 KB Output is correct
15 Correct 3 ms 10320 KB Output is correct
16 Correct 3 ms 10072 KB Output is correct
17 Correct 3 ms 10072 KB Output is correct
18 Correct 2 ms 10172 KB Output is correct
19 Correct 3 ms 10072 KB Output is correct
20 Correct 3 ms 10072 KB Output is correct
21 Correct 3 ms 10072 KB Output is correct
22 Correct 4 ms 10328 KB Output is correct
23 Correct 3 ms 10072 KB Output is correct
24 Correct 13 ms 10432 KB Output is correct
25 Correct 40 ms 10328 KB Output is correct
26 Correct 54 ms 10328 KB Output is correct
27 Correct 62 ms 10656 KB Output is correct
28 Correct 23 ms 10328 KB Output is correct
29 Correct 46 ms 10348 KB Output is correct
30 Correct 257 ms 11412 KB Output is correct
31 Correct 138 ms 10432 KB Output is correct
32 Correct 162 ms 13180 KB Output is correct
33 Correct 110 ms 11224 KB Output is correct
34 Correct 1724 ms 13600 KB Output is correct
35 Execution timed out 4101 ms 11544 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 10072 KB Output is correct
4 Correct 3 ms 10072 KB Output is correct
5 Correct 3 ms 10072 KB Output is correct
6 Correct 3 ms 10072 KB Output is correct
7 Correct 3 ms 10072 KB Output is correct
8 Correct 3 ms 10072 KB Output is correct
9 Correct 2 ms 10072 KB Output is correct
10 Correct 2 ms 10072 KB Output is correct
11 Correct 3 ms 10072 KB Output is correct
12 Correct 2 ms 10172 KB Output is correct
13 Correct 4 ms 10072 KB Output is correct
14 Correct 3 ms 10072 KB Output is correct
15 Correct 3 ms 10320 KB Output is correct
16 Correct 3 ms 10072 KB Output is correct
17 Correct 3 ms 10072 KB Output is correct
18 Correct 2 ms 10172 KB Output is correct
19 Correct 3 ms 10072 KB Output is correct
20 Correct 3 ms 10072 KB Output is correct
21 Correct 3 ms 10072 KB Output is correct
22 Correct 4 ms 10328 KB Output is correct
23 Correct 3 ms 10072 KB Output is correct
24 Correct 13 ms 10432 KB Output is correct
25 Correct 40 ms 10328 KB Output is correct
26 Correct 54 ms 10328 KB Output is correct
27 Correct 62 ms 10656 KB Output is correct
28 Correct 23 ms 10328 KB Output is correct
29 Correct 46 ms 10348 KB Output is correct
30 Correct 257 ms 11412 KB Output is correct
31 Correct 138 ms 10432 KB Output is correct
32 Correct 162 ms 13180 KB Output is correct
33 Correct 110 ms 11224 KB Output is correct
34 Correct 1724 ms 13600 KB Output is correct
35 Execution timed out 4101 ms 11544 KB Time limit exceeded
36 Halted 0 ms 0 KB -