답안 #1047404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047404 2024-08-07T12:36:12 Z becaido 장난감 기차 (IOI17_train) C++17
100 / 100
150 ms 1880 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#include "grader.cpp"
#else
#include "train.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int SIZE = 5005;

int n, m;
int ans[SIZE], d[SIZE];
bool alice[SIZE], is[SIZE];
vector<int> adj[SIZE], rev[SIZE];

bool vs[SIZE];
int deg[SIZE];
vector<int> cal(vector<int> v, bool x) {
    fill(vs + 1, vs + n + 1, 0);
    fill(deg + 1, deg + n + 1, 0);
    queue<int> q;
    for (int pos : v) {
        q.push(pos);
        vs[pos] = 1;
    }
    while (q.size()) {
        int pos = q.front();
        q.pop();
        for (int lp : rev[pos]) if (vs[lp] == 0 && ans[lp] == 0 && (alice[lp] == x || ++deg[lp] == d[lp])) {
            q.push(lp);
            vs[lp] = 1;
        }
    }
    v.clear();
    FOR (i, 1, n) if (vs[i]) v.pb(i);
    return v;
}

vector<int> who_wins(vector<int> a_, vector<int> r_, vector<int> u, vector<int> v) {
    n = a_.size();
    m = u.size();
    FOR (i, 1, n) {
        alice[i] = a_[i - 1];
        is[i] = r_[i - 1];
        adj[i].clear();
        rev[i].clear();
        ans[i] = d[i] = 0;
    }
    FOR (i, 0, m - 1) {
        u[i]++, v[i]++;
        d[u[i]]++;
        adj[u[i]].pb(v[i]);
        rev[v[i]].pb(u[i]);
    }
    while (true) {
        int cnt = 0;
        FOR (i, 1, n) if (ans[i] == 0) cnt++;
        if (cnt == 0) break;
        vector<int> A, B;
        FOR (i, 1, n) if (is[i] && ans[i] == 0) A.pb(i);
        A = cal(A, 1);
        if (A.size() == cnt) {
            for (int x : A) ans[x] = 1;
            break;
        }
        for (int i = 1, j = 0; i <= n; i++) if (ans[i] == 0) {
            while (j < A.size() && A[j] < i) j++;
            if (j < A.size() && A[j] == i) continue;
            B.pb(i);
        }
        B = cal(B, 0);
        for (int x : B) {
            ans[x] = 2;
            for (int lp : rev[x]) d[lp]--;
        }
    }
    vector<int> res;
    FOR (i, 1, n) res.pb(ans[i] == 1 ? 1 : 0);
    return res;
}

/*
in1
2 4
0 1
1 0
0 0
0 1
1 0
1 1
out1
1 1
*/

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:81:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |         if (A.size() == cnt) {
      |             ~~~~~~~~~^~~~~~
train.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |             while (j < A.size() && A[j] < i) j++;
      |                    ~~^~~~~~~~~~
train.cpp:87:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             if (j < A.size() && A[j] == i) continue;
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1368 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 3 ms 1372 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 1416 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 4 ms 1116 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 680 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1880 KB Output is correct
2 Correct 94 ms 1860 KB Output is correct
3 Correct 84 ms 1872 KB Output is correct
4 Correct 5 ms 1624 KB Output is correct
5 Correct 5 ms 1652 KB Output is correct
6 Correct 5 ms 1628 KB Output is correct
7 Correct 5 ms 1596 KB Output is correct
8 Correct 4 ms 1628 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1568 KB Output is correct
12 Correct 4 ms 1724 KB Output is correct
13 Correct 10 ms 1624 KB Output is correct
14 Correct 4 ms 1628 KB Output is correct
15 Correct 4 ms 1628 KB Output is correct
16 Correct 5 ms 1628 KB Output is correct
17 Correct 4 ms 1808 KB Output is correct
18 Correct 145 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1456 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 4 ms 1596 KB Output is correct
4 Correct 5 ms 1800 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 4 ms 1628 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 4 ms 1612 KB Output is correct
9 Correct 4 ms 1736 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 5 ms 1628 KB Output is correct
14 Correct 4 ms 1568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1624 KB Output is correct
2 Correct 4 ms 1756 KB Output is correct
3 Correct 5 ms 1752 KB Output is correct
4 Correct 4 ms 1628 KB Output is correct
5 Correct 1 ms 860 KB Output is correct
6 Correct 2 ms 1372 KB Output is correct
7 Correct 4 ms 1192 KB Output is correct
8 Correct 3 ms 1340 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1368 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 3 ms 1372 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 1416 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 2 ms 1372 KB Output is correct
10 Correct 4 ms 1116 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 680 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 0 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 35 ms 1880 KB Output is correct
33 Correct 94 ms 1860 KB Output is correct
34 Correct 84 ms 1872 KB Output is correct
35 Correct 5 ms 1624 KB Output is correct
36 Correct 5 ms 1652 KB Output is correct
37 Correct 5 ms 1628 KB Output is correct
38 Correct 5 ms 1596 KB Output is correct
39 Correct 4 ms 1628 KB Output is correct
40 Correct 4 ms 1628 KB Output is correct
41 Correct 4 ms 1628 KB Output is correct
42 Correct 4 ms 1568 KB Output is correct
43 Correct 4 ms 1724 KB Output is correct
44 Correct 10 ms 1624 KB Output is correct
45 Correct 4 ms 1628 KB Output is correct
46 Correct 4 ms 1628 KB Output is correct
47 Correct 5 ms 1628 KB Output is correct
48 Correct 4 ms 1808 KB Output is correct
49 Correct 145 ms 1368 KB Output is correct
50 Correct 4 ms 1456 KB Output is correct
51 Correct 4 ms 1628 KB Output is correct
52 Correct 4 ms 1596 KB Output is correct
53 Correct 5 ms 1800 KB Output is correct
54 Correct 4 ms 1628 KB Output is correct
55 Correct 4 ms 1628 KB Output is correct
56 Correct 4 ms 1628 KB Output is correct
57 Correct 4 ms 1612 KB Output is correct
58 Correct 4 ms 1736 KB Output is correct
59 Correct 4 ms 1628 KB Output is correct
60 Correct 4 ms 1628 KB Output is correct
61 Correct 4 ms 1628 KB Output is correct
62 Correct 5 ms 1628 KB Output is correct
63 Correct 4 ms 1568 KB Output is correct
64 Correct 5 ms 1624 KB Output is correct
65 Correct 4 ms 1756 KB Output is correct
66 Correct 5 ms 1752 KB Output is correct
67 Correct 4 ms 1628 KB Output is correct
68 Correct 1 ms 860 KB Output is correct
69 Correct 2 ms 1372 KB Output is correct
70 Correct 4 ms 1192 KB Output is correct
71 Correct 3 ms 1340 KB Output is correct
72 Correct 3 ms 1372 KB Output is correct
73 Correct 1 ms 860 KB Output is correct
74 Correct 2 ms 1116 KB Output is correct
75 Correct 56 ms 1832 KB Output is correct
76 Correct 83 ms 1876 KB Output is correct
77 Correct 113 ms 1628 KB Output is correct
78 Correct 104 ms 1872 KB Output is correct
79 Correct 100 ms 1876 KB Output is correct
80 Correct 5 ms 1624 KB Output is correct
81 Correct 5 ms 1628 KB Output is correct
82 Correct 5 ms 1628 KB Output is correct
83 Correct 5 ms 1604 KB Output is correct
84 Correct 5 ms 1624 KB Output is correct
85 Correct 5 ms 1628 KB Output is correct
86 Correct 5 ms 1596 KB Output is correct
87 Correct 5 ms 1760 KB Output is correct
88 Correct 7 ms 1720 KB Output is correct
89 Correct 5 ms 1624 KB Output is correct
90 Correct 7 ms 1804 KB Output is correct
91 Correct 7 ms 1624 KB Output is correct
92 Correct 12 ms 1824 KB Output is correct
93 Correct 11 ms 1624 KB Output is correct
94 Correct 11 ms 1836 KB Output is correct
95 Correct 12 ms 1624 KB Output is correct
96 Correct 28 ms 1720 KB Output is correct
97 Correct 91 ms 1624 KB Output is correct
98 Correct 137 ms 1804 KB Output is correct
99 Correct 150 ms 1808 KB Output is correct
100 Correct 121 ms 1464 KB Output is correct