답안 #799825

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799825 2023-08-01T05:34:24 Z PixelCat 장난감 기차 (IOI17_train) C++14
100 / 100
699 ms 2048 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) {
        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);
    vector<int> stations;
    For(i, 0, n - 1) if(r[i]) stations.eb(i);
    For(i, 0, m - 1) {
        int x = u[i];
        int y = v[i];
        adj[x].eb(y);
    }
    For(i, 0, n - 1) alive[i] = 1;
    int node_cnt = n;
    while(node_cnt) {
        build_graph(n);
        int cnt2 = walk(n, a, stations, 1);
        if(cnt2 == node_cnt) break;
        // For(i, 0, n - 1) cerr << tag[i] << " \n"[i == n - 1];
        vector<int> s;
        For(i, 0, n - 1) if(alive[i] && !tag[i]) s.eb(i);
        int cnt3 = walk(n, a, s, 0);
        For(i, 0, n - 1) alive[i] = alive[i] && (!tag[i]);
        node_cnt -= cnt3;
    }
    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

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1236 KB Output is correct
2 Correct 6 ms 1228 KB Output is correct
3 Correct 4 ms 1324 KB Output is correct
4 Correct 5 ms 1228 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 4 ms 1228 KB Output is correct
7 Correct 4 ms 1312 KB Output is correct
8 Correct 6 ms 1228 KB Output is correct
9 Correct 4 ms 1228 KB Output is correct
10 Correct 4 ms 1308 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 544 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 544 KB Output is correct
15 Correct 1 ms 540 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 544 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 2028 KB Output is correct
2 Correct 308 ms 2008 KB Output is correct
3 Correct 426 ms 1984 KB Output is correct
4 Correct 7 ms 1952 KB Output is correct
5 Correct 9 ms 1836 KB Output is correct
6 Correct 7 ms 1876 KB Output is correct
7 Correct 6 ms 2024 KB Output is correct
8 Correct 6 ms 1876 KB Output is correct
9 Correct 6 ms 1836 KB Output is correct
10 Correct 6 ms 1836 KB Output is correct
11 Correct 6 ms 1748 KB Output is correct
12 Correct 6 ms 1748 KB Output is correct
13 Correct 6 ms 1876 KB Output is correct
14 Correct 6 ms 1876 KB Output is correct
15 Correct 6 ms 1876 KB Output is correct
16 Correct 6 ms 1876 KB Output is correct
17 Correct 6 ms 1876 KB Output is correct
18 Correct 415 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1620 KB Output is correct
2 Correct 7 ms 1700 KB Output is correct
3 Correct 6 ms 1964 KB Output is correct
4 Correct 7 ms 2004 KB Output is correct
5 Correct 6 ms 1876 KB Output is correct
6 Correct 6 ms 1876 KB Output is correct
7 Correct 6 ms 1840 KB Output is correct
8 Correct 6 ms 1952 KB Output is correct
9 Correct 6 ms 1748 KB Output is correct
10 Correct 6 ms 1876 KB Output is correct
11 Correct 8 ms 1972 KB Output is correct
12 Correct 6 ms 1876 KB Output is correct
13 Correct 6 ms 1968 KB Output is correct
14 Correct 6 ms 1800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1876 KB Output is correct
2 Correct 6 ms 1876 KB Output is correct
3 Correct 7 ms 1876 KB Output is correct
4 Correct 6 ms 1712 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 4 ms 1492 KB Output is correct
8 Correct 4 ms 1620 KB Output is correct
9 Correct 4 ms 1504 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 4 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1236 KB Output is correct
2 Correct 6 ms 1228 KB Output is correct
3 Correct 4 ms 1324 KB Output is correct
4 Correct 5 ms 1228 KB Output is correct
5 Correct 4 ms 1236 KB Output is correct
6 Correct 4 ms 1228 KB Output is correct
7 Correct 4 ms 1312 KB Output is correct
8 Correct 6 ms 1228 KB Output is correct
9 Correct 4 ms 1228 KB Output is correct
10 Correct 4 ms 1308 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 544 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 544 KB Output is correct
26 Correct 1 ms 540 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 544 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 150 ms 2028 KB Output is correct
33 Correct 308 ms 2008 KB Output is correct
34 Correct 426 ms 1984 KB Output is correct
35 Correct 7 ms 1952 KB Output is correct
36 Correct 9 ms 1836 KB Output is correct
37 Correct 7 ms 1876 KB Output is correct
38 Correct 6 ms 2024 KB Output is correct
39 Correct 6 ms 1876 KB Output is correct
40 Correct 6 ms 1836 KB Output is correct
41 Correct 6 ms 1836 KB Output is correct
42 Correct 6 ms 1748 KB Output is correct
43 Correct 6 ms 1748 KB Output is correct
44 Correct 6 ms 1876 KB Output is correct
45 Correct 6 ms 1876 KB Output is correct
46 Correct 6 ms 1876 KB Output is correct
47 Correct 6 ms 1876 KB Output is correct
48 Correct 6 ms 1876 KB Output is correct
49 Correct 415 ms 1408 KB Output is correct
50 Correct 5 ms 1620 KB Output is correct
51 Correct 7 ms 1700 KB Output is correct
52 Correct 6 ms 1964 KB Output is correct
53 Correct 7 ms 2004 KB Output is correct
54 Correct 6 ms 1876 KB Output is correct
55 Correct 6 ms 1876 KB Output is correct
56 Correct 6 ms 1840 KB Output is correct
57 Correct 6 ms 1952 KB Output is correct
58 Correct 6 ms 1748 KB Output is correct
59 Correct 6 ms 1876 KB Output is correct
60 Correct 8 ms 1972 KB Output is correct
61 Correct 6 ms 1876 KB Output is correct
62 Correct 6 ms 1968 KB Output is correct
63 Correct 6 ms 1800 KB Output is correct
64 Correct 7 ms 1876 KB Output is correct
65 Correct 6 ms 1876 KB Output is correct
66 Correct 7 ms 1876 KB Output is correct
67 Correct 6 ms 1712 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 3 ms 1364 KB Output is correct
70 Correct 4 ms 1492 KB Output is correct
71 Correct 4 ms 1620 KB Output is correct
72 Correct 4 ms 1504 KB Output is correct
73 Correct 1 ms 852 KB Output is correct
74 Correct 4 ms 1364 KB Output is correct
75 Correct 143 ms 2036 KB Output is correct
76 Correct 263 ms 2048 KB Output is correct
77 Correct 354 ms 1928 KB Output is correct
78 Correct 368 ms 1936 KB Output is correct
79 Correct 362 ms 1940 KB Output is correct
80 Correct 8 ms 1876 KB Output is correct
81 Correct 7 ms 1876 KB Output is correct
82 Correct 7 ms 1876 KB Output is correct
83 Correct 8 ms 1924 KB Output is correct
84 Correct 8 ms 1876 KB Output is correct
85 Correct 7 ms 1840 KB Output is correct
86 Correct 8 ms 1876 KB Output is correct
87 Correct 7 ms 1968 KB Output is correct
88 Correct 10 ms 1876 KB Output is correct
89 Correct 7 ms 1876 KB Output is correct
90 Correct 16 ms 1840 KB Output is correct
91 Correct 12 ms 1936 KB Output is correct
92 Correct 25 ms 1876 KB Output is correct
93 Correct 23 ms 1876 KB Output is correct
94 Correct 24 ms 1880 KB Output is correct
95 Correct 26 ms 1912 KB Output is correct
96 Correct 84 ms 1748 KB Output is correct
97 Correct 400 ms 1968 KB Output is correct
98 Correct 638 ms 1920 KB Output is correct
99 Correct 699 ms 1924 KB Output is correct
100 Correct 406 ms 1364 KB Output is correct