Submission #799809

# Submission time Handle Problem Language Result Execution time Memory
799809 2023-08-01T04:44:09 Z PixelCat Toy Train (IOI17_train) C++14
0 / 100
2000 ms 2612 KB
#ifdef NYAOWO
#include "grader.cpp"
#endif

#include "train.h"

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 5000;

vector<int> adj[MAXN + 10];
vector<int> rev[MAXN + 10];
int odeg[MAXN + 10];
int alive[MAXN + 10];
int tag[MAXN + 10];

void build_graph(int n) {
    For(i, 0, n - 1) {
        odeg[i] = 0;
        rev[i].clear();
        if(!alive[i]) adj[i].clear();
    }
    For(i, 0, n - 1) if(alive[i]) {
        int ptr = 0;
        while(ptr < sz(adj[i])) {
            if(alive[adj[i][ptr]]) ptr++;
            else {
                swap(adj[i][ptr], adj[i].back());
                adj[i].pop_back();
            }
        }
    }
    For(i, 0, n - 1) for(auto &j:adj[i]) {
        rev[j].eb(i);
    }
}

int walk(int n, vector<i32> a, vector<int> s, int c) {
    For(i, 0, n - 1) {
        odeg[i] = sz(adj[i]);
        tag[i] = 0;
    }
    queue<int> que;
    for(auto &i:s) if(alive[i]) que.emplace(i);
    int cnt = 0;
    while(!que.empty()) {
        int cur = que.front(); que.pop();
        if(tag[cur]) continue;
        tag[cur] = 1;
        cnt++;
        for(auto &i:rev[cur]) {
            odeg[i]--;
            if(a[i] == c) {
                que.emplace(i);
            } else if(odeg[i] == 0) {
                que.emplace(i);
            }
        }
    }
    return cnt;
}

vector<i32> who_wins(vector<i32> a, vector<i32> r, vector<i32> u, vector<i32> v) {
    int n = sz(a);
    int m = sz(u);
    For(i, 0, m - 1) {
        int x = u[i];
        int y = v[i];
        adj[x].eb(y);
        adj[y].eb(x);
    }
    For(i, 0, n - 1) alive[i] = 1;
    int node_cnt = n;
    while(true) {
        build_graph(n);
        int cnt2 = walk(n, a, vector<int>(all(r)), 1);
        if(cnt2 == node_cnt) break;
        vector<int> s;
        For(i, 0, n - 1) if(alive[i] && !tag[i]) s.eb(i);
        ignore = walk(n, a, s, 0);
        For(i, 0, n - 1) alive[i] = alive[i] && (!tag[i]);
    }
    vector<i32> w;
    For(i, 0, n - 1) w.eb(alive[i]);
    return w;
}

/*

2 4
0 1
1 0
0 0
0 1
1 0
1 1

1 1

*/
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 1364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2516 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 Execution timed out 2063 ms 2224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2054 ms 2612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 1364 KB Time limit exceeded
2 Halted 0 ms 0 KB -