Submission #555817

# Submission time Handle Problem Language Result Execution time Memory
555817 2022-05-01T15:31:55 Z Lemur95 Toy Train (IOI17_train) C++17
100 / 100
664 ms 1784 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <cstring>
#include <chrono>
#include <cassert>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <random>
#include "train.h"

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif

//#pragma GCC optimize("Ofast")
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define x first
#define y second
#define ld long double
#define ll long long
#define ull unsigned long long
#define us unsigned short
#define lsb(x) ((x) & (-(x)))
#define pii pair <int, int>
#define pll pair <ll, ll>

using namespace std;

ifstream in("test.in");
ofstream out("test.out");

mt19937 gen(time(0));
uniform_int_distribution <uint32_t> rng;

const int MOD = (int)1e9 + 7;

ll gcd(ll a, ll b) {
    if (!b)
        return a;
    return gcd(b, a % b);
}

int n, m;

int s[200005], f[200005];
int st[200005];
ll dp[200005];

vector <int> who_wins(vector <int> a, vector <int> r, vector <int> u, vector <int> v) {
    n = a.size(), m = u.size();

    vector <int> g[5005], gr[5005];
    vector <int> in(n);

    for (int i = 0; i < m; i++) {
        g[u[i]].push_back(v[i]);
        gr[v[i]].push_back(u[i]);
    }

    while (true) {
        queue <int> q;
        vector <int> cnt(n);

        fill(cnt.begin(), cnt.end(), 0);
        vector <int> s = r;

        for (int i = 0; i < n; i++) {
            if (r[i])
                q.push(i);
        }

        while (!q.empty()) {
            int nod = q.front();
            q.pop();

            for (auto& fiu : gr[nod]) {
                cnt[fiu]++;

                if (!s[fiu]) {
                    if (a[fiu] && cnt[fiu]) {
                        s[fiu] = 1;
                        q.push(fiu);
                    }
                    else if (!a[fiu] && cnt[fiu] == g[fiu].size()) {
                        s[fiu] = 1;
                        q.push(fiu);
                    }
                }
            }
        }

        for (int i = 0; i < n; i++) {
            if (!s[i])
                q.push(i);
            s[i] ^= 1;
        }

        fill(cnt.begin(), cnt.end(), 0);

        while (!q.empty()) {
            int nod = q.front();
            q.pop();

            for (auto& fiu : gr[nod]) {
                cnt[fiu]++;

                if (!s[fiu]) {
                    if (!a[fiu] && cnt[fiu]) {
                        s[fiu] = 1;
                        q.push(fiu);
                    }
                    else if (a[fiu] && cnt[fiu] == g[fiu].size()) {
                        s[fiu] = 1;
                        q.push(fiu);
                    }
                }
            }
        }

        bool flag = 1;
        for (int i = 0; i < n; i++) {
            if (r[i] && s[i])
                r[i] = 0, flag = 0;
        }

        if (flag) {
            vector <int> ans(n);

            for (int i = 0; i < n; i++)
                ans[i] = s[i] ^ 1;

            return ans;
        }
    }
}

/*void solve() {
    int n, m;
    cin >> n >> m;

    vector <int> a(n), r(n), u(m), v(m);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> r[i];
    }

    for (int i = 0; i < m; i++) {
        cin >> u[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> v[i];
    }

    vector <int> ans = who_wins(a, r, u, v);

    for (auto& i : ans)
        cout << i << " ";
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    srand(time(0));

    int T = 1;

    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}*/

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:95:50: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |                     else if (!a[fiu] && cnt[fiu] == g[fiu].size()) {
train.cpp:123:49: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |                     else if (a[fiu] && cnt[fiu] == g[fiu].size()) {
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 5 ms 1224 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 4 ms 1228 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
# Verdict Execution time Memory 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 452 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 452 KB Output is correct
9 Correct 1 ms 448 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 456 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 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
# Verdict Execution time Memory Grader output
1 Correct 97 ms 1464 KB Output is correct
2 Correct 192 ms 1456 KB Output is correct
3 Correct 297 ms 1452 KB Output is correct
4 Correct 7 ms 1364 KB Output is correct
5 Correct 12 ms 1620 KB Output is correct
6 Correct 9 ms 1620 KB Output is correct
7 Correct 8 ms 1620 KB Output is correct
8 Correct 7 ms 1620 KB Output is correct
9 Correct 7 ms 1620 KB Output is correct
10 Correct 7 ms 1616 KB Output is correct
11 Correct 7 ms 1492 KB Output is correct
12 Correct 6 ms 1492 KB Output is correct
13 Correct 7 ms 1620 KB Output is correct
14 Correct 11 ms 1656 KB Output is correct
15 Correct 8 ms 1660 KB Output is correct
16 Correct 7 ms 1652 KB Output is correct
17 Correct 7 ms 1620 KB Output is correct
18 Correct 435 ms 1288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1236 KB Output is correct
2 Correct 6 ms 1236 KB Output is correct
3 Correct 8 ms 1364 KB Output is correct
4 Correct 7 ms 1364 KB Output is correct
5 Correct 8 ms 1536 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 7 ms 1408 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 9 ms 1364 KB Output is correct
10 Correct 7 ms 1408 KB Output is correct
11 Correct 7 ms 1408 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 7 ms 1364 KB Output is correct
14 Correct 7 ms 1320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1364 KB Output is correct
2 Correct 8 ms 1620 KB Output is correct
3 Correct 7 ms 1624 KB Output is correct
4 Correct 8 ms 1488 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 5 ms 1236 KB Output is correct
9 Correct 5 ms 1236 KB Output is correct
10 Correct 2 ms 660 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 5 ms 1224 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 4 ms 1228 KB Output is correct
8 Correct 5 ms 1108 KB Output is correct
9 Correct 4 ms 1108 KB Output is correct
10 Correct 4 ms 1108 KB Output is correct
11 Correct 4 ms 1108 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 452 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 452 KB Output is correct
20 Correct 1 ms 448 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 456 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 97 ms 1464 KB Output is correct
33 Correct 192 ms 1456 KB Output is correct
34 Correct 297 ms 1452 KB Output is correct
35 Correct 7 ms 1364 KB Output is correct
36 Correct 12 ms 1620 KB Output is correct
37 Correct 9 ms 1620 KB Output is correct
38 Correct 8 ms 1620 KB Output is correct
39 Correct 7 ms 1620 KB Output is correct
40 Correct 7 ms 1620 KB Output is correct
41 Correct 7 ms 1616 KB Output is correct
42 Correct 7 ms 1492 KB Output is correct
43 Correct 6 ms 1492 KB Output is correct
44 Correct 7 ms 1620 KB Output is correct
45 Correct 11 ms 1656 KB Output is correct
46 Correct 8 ms 1660 KB Output is correct
47 Correct 7 ms 1652 KB Output is correct
48 Correct 7 ms 1620 KB Output is correct
49 Correct 435 ms 1288 KB Output is correct
50 Correct 6 ms 1236 KB Output is correct
51 Correct 6 ms 1236 KB Output is correct
52 Correct 8 ms 1364 KB Output is correct
53 Correct 7 ms 1364 KB Output is correct
54 Correct 8 ms 1536 KB Output is correct
55 Correct 7 ms 1364 KB Output is correct
56 Correct 7 ms 1408 KB Output is correct
57 Correct 7 ms 1364 KB Output is correct
58 Correct 9 ms 1364 KB Output is correct
59 Correct 7 ms 1408 KB Output is correct
60 Correct 7 ms 1408 KB Output is correct
61 Correct 8 ms 1364 KB Output is correct
62 Correct 7 ms 1364 KB Output is correct
63 Correct 7 ms 1320 KB Output is correct
64 Correct 7 ms 1364 KB Output is correct
65 Correct 8 ms 1620 KB Output is correct
66 Correct 7 ms 1624 KB Output is correct
67 Correct 8 ms 1488 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 5 ms 1108 KB Output is correct
70 Correct 6 ms 1228 KB Output is correct
71 Correct 5 ms 1236 KB Output is correct
72 Correct 5 ms 1236 KB Output is correct
73 Correct 2 ms 660 KB Output is correct
74 Correct 5 ms 1108 KB Output is correct
75 Correct 150 ms 1624 KB Output is correct
76 Correct 212 ms 1660 KB Output is correct
77 Correct 326 ms 1784 KB Output is correct
78 Correct 322 ms 1664 KB Output is correct
79 Correct 353 ms 1664 KB Output is correct
80 Correct 8 ms 1620 KB Output is correct
81 Correct 7 ms 1620 KB Output is correct
82 Correct 9 ms 1636 KB Output is correct
83 Correct 8 ms 1660 KB Output is correct
84 Correct 9 ms 1620 KB Output is correct
85 Correct 9 ms 1624 KB Output is correct
86 Correct 9 ms 1620 KB Output is correct
87 Correct 8 ms 1620 KB Output is correct
88 Correct 11 ms 1620 KB Output is correct
89 Correct 8 ms 1656 KB Output is correct
90 Correct 14 ms 1620 KB Output is correct
91 Correct 14 ms 1624 KB Output is correct
92 Correct 24 ms 1616 KB Output is correct
93 Correct 23 ms 1628 KB Output is correct
94 Correct 24 ms 1620 KB Output is correct
95 Correct 25 ms 1628 KB Output is correct
96 Correct 68 ms 1532 KB Output is correct
97 Correct 398 ms 1636 KB Output is correct
98 Correct 583 ms 1596 KB Output is correct
99 Correct 664 ms 1620 KB Output is correct
100 Correct 433 ms 1284 KB Output is correct