Submission #1064315

# Submission time Handle Problem Language Result Execution time Memory
1064315 2024-08-18T11:24:10 Z TheQuantiX Toy Train (IOI17_train) C++17
17 / 100
10 ms 2684 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll INF = 1000000000000000000LL;

ll n, m, q, k, x, y, a, c;
vector<ll> G[5000];
vector<ll> Gr[5000];

vector<int> get_total(vector<int> a, vector<int> r, vector<int> u, vector<int> v, vector<ll> cnt) {
    queue<ll> q;
    vector<int> vis(n);
    for (int i = 0; i < n; i++) {
        if (r[i]) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        ll x = q.front();
        q.pop();
        if (vis[x]) {
            continue;
        }
        vis[x] = 1;
        for (auto i : G[x]) {
            if (a[i] && !vis[i]) {
                q.push(i);
            }
            if (!a[i]) {
                cnt[i]--;
                if (cnt[i] == 0 && !vis[i]) {
                    q.push(i);
                }
            }
        }
    }
    return vis;
}

vector<int> solve1(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    vector<int> ans(n);
    for (int i = n - 1; i >= 0; i--) {
        if (r[i]) {
            ans[i] = 1;
        }
        bool fl;
        if (a[i]) {
            fl = 0;
            for (auto j : Gr[i]) {
                if (ans[j]) {
                    fl = 1;
                    break;
                }
            }
        }
        else {
            fl = 1;
            for (auto j : Gr[i]) {
                if (!ans[j]) {
                    fl = 0;
                    break;
                }
            }
        }
        ans[i] = fl;
    }
    return ans;
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    n = a.size();
    m = u.size();
    vector<ll> cnt(n);
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        G[i].clear();
        Gr[i].clear();
    }
    set<ll> st;
    for (int i = 0; i < m; i++) {
        cnt[u[i]]++;
        st.insert(v[i] - u[i]);
        G[v[i]].push_back(u[i]);
        Gr[u[i]].push_back(v[i]);
    }
    if (st.count(0)) {
        st.erase(0);
    }
    if (st.count(1)) {
        st.erase(1);
    }
    if (st.size() == 0) {
        return solve1(a, r, u, v);
    }
    vector<int> total = get_total(a, r, u, v, cnt);
    // for (int i = 0; i < n; i++) {
    //     cout << total[i] << ' ';
    // }
    // cout << '\n';
    vector<int> possible(n);
    auto cnt1 = cnt;
    for (int i = 0; i < n; i++) {
        if (r[i]) {
            bool fl;
            if (a[i]) {
                fl = 0;
                for (int j : Gr[i]) {
                    if (total[j]) {
                        fl = 1;
                        break;
                    }
                }
            }
            else {
                fl = 1;
                for (int j : Gr[i]) {
                    if (!total[j]) {
                        fl = 0;
                        break;
                    }
                }
            }
            possible[i] = fl;
        }
    }
    return get_total(a, possible, u, v, cnt);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 3 ms 1368 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 3 ms 1368 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 3 ms 1364 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1196 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Incorrect 0 ms 604 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2600 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2140 KB Output is correct
2 Correct 10 ms 2396 KB Output is correct
3 Incorrect 9 ms 2480 KB 3rd lines differ - on the 108th token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2652 KB Output is correct
2 Correct 9 ms 2684 KB Output is correct
3 Correct 8 ms 2628 KB Output is correct
4 Correct 8 ms 2396 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 4 ms 1628 KB Output is correct
7 Correct 5 ms 1628 KB Output is correct
8 Correct 5 ms 1876 KB Output is correct
9 Correct 5 ms 1888 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 5 ms 1596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 3 ms 1368 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 3 ms 1368 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 3 ms 1364 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1196 KB Output is correct
11 Correct 3 ms 1372 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 0 ms 604 KB 3rd lines differ - on the 4th token, expected: '0', found: '1'
16 Halted 0 ms 0 KB -