Submission #269697

# Submission time Handle Problem Language Result Execution time Memory
269697 2020-08-17T08:40:45 Z hamerin Toy Train (IOI17_train) C++17
100 / 100
1941 ms 1452 KB
#include "train.h"

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;

#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u,
                     vector<int> v) {
    const size_t N = a.size();
    const size_t M = u.size();

    vector<vector<int>> invGraph(N);
    vector<int> outdeg(N);
    for (auto i = 0; i < M; i++) {
        invGraph[v[i]].emplace_back(u[i]);
        outdeg[u[i]]++;
    }

    vector<bool> notBWin(N);

    // 몰라 대충 N번 돌리면 되겠지
    for (auto __loop = 0; __loop < N; __loop++) {
        vector<int> curoutdeg(N);
        queue<int> que;

        fill(iterall(notBWin), false);
        for (auto i = 0; i < N; i++)
            if (r[i]) que.emplace(i), notBWin[i] = true;
        while (!que.empty()) {
            auto cur = que.front();
            que.pop();

            for (auto el : invGraph[cur]) {
                if (notBWin[el]) continue;

                curoutdeg[el]++;
                if (a[el] || (!a[el] && curoutdeg[el] == outdeg[el])) {
                    notBWin[el] = true;
                    que.emplace(el);
                }
            }
        }

        fill(iterall(curoutdeg), 0);
        for (auto i = 0; i < N; i++)
            if (!notBWin[i]) que.emplace(i);
        while (!que.empty()) {
            auto cur = que.front();
            que.pop();

            for (auto el : invGraph[cur]) {
                if (!notBWin[el]) continue;

                curoutdeg[el]++;
                if (!a[el] || (a[el] && curoutdeg[el] == outdeg[el])) {
                    notBWin[el] = false;
                    que.emplace(el);
                }
            }
        }

		for(int i=0;i<N;i++) if(!notBWin[i] && r[i]) r[i] = false;
    }

	vector<int> ret;
	copy(iterall(notBWin), back_inserter(ret));

    return ret;
}

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:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   27 |     for (auto i = 0; i < M; i++) {
      |                      ~~^~~
train.cpp:35:34: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   35 |     for (auto __loop = 0; __loop < N; __loop++) {
      |                           ~~~~~~~^~~
train.cpp:40:28: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   40 |         for (auto i = 0; i < N; i++)
      |                          ~~^~~
train.cpp:58:28: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   58 |         for (auto i = 0; i < N; i++)
      |                          ~~^~~
train.cpp:75:16: warning: comparison of integer expressions of different signedness: 'int' and 'const size_t' {aka 'const long unsigned int'} [-Wsign-compare]
   75 |   for(int i=0;i<N;i++) if(!notBWin[i] && r[i]) r[i] = false;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 760 ms 1016 KB Output is correct
2 Correct 749 ms 1016 KB Output is correct
3 Correct 744 ms 1016 KB Output is correct
4 Correct 726 ms 952 KB Output is correct
5 Correct 709 ms 896 KB Output is correct
6 Correct 752 ms 896 KB Output is correct
7 Correct 545 ms 1024 KB Output is correct
8 Correct 787 ms 1016 KB Output is correct
9 Correct 802 ms 924 KB Output is correct
10 Correct 839 ms 1016 KB Output is correct
11 Correct 647 ms 924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 566 ms 1280 KB Output is correct
2 Correct 628 ms 1408 KB Output is correct
3 Correct 685 ms 1400 KB Output is correct
4 Correct 1186 ms 1400 KB Output is correct
5 Correct 1384 ms 1336 KB Output is correct
6 Correct 792 ms 1348 KB Output is correct
7 Correct 1064 ms 1340 KB Output is correct
8 Correct 1338 ms 1340 KB Output is correct
9 Correct 770 ms 1424 KB Output is correct
10 Correct 1316 ms 1300 KB Output is correct
11 Correct 1382 ms 1400 KB Output is correct
12 Correct 712 ms 1272 KB Output is correct
13 Correct 1121 ms 1336 KB Output is correct
14 Correct 1196 ms 1356 KB Output is correct
15 Correct 1095 ms 1348 KB Output is correct
16 Correct 1135 ms 1340 KB Output is correct
17 Correct 1092 ms 1280 KB Output is correct
18 Correct 550 ms 1048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 771 ms 1168 KB Output is correct
2 Correct 1368 ms 1228 KB Output is correct
3 Correct 754 ms 1320 KB Output is correct
4 Correct 750 ms 1340 KB Output is correct
5 Correct 1266 ms 1332 KB Output is correct
6 Correct 1481 ms 1312 KB Output is correct
7 Correct 1491 ms 1308 KB Output is correct
8 Correct 769 ms 1400 KB Output is correct
9 Correct 1253 ms 1260 KB Output is correct
10 Correct 1375 ms 1400 KB Output is correct
11 Correct 991 ms 1356 KB Output is correct
12 Correct 1334 ms 1360 KB Output is correct
13 Correct 1393 ms 1328 KB Output is correct
14 Correct 1530 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1702 ms 1336 KB Output is correct
2 Correct 1534 ms 1336 KB Output is correct
3 Correct 1941 ms 1280 KB Output is correct
4 Correct 1629 ms 1244 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 524 ms 896 KB Output is correct
7 Correct 67 ms 896 KB Output is correct
8 Correct 27 ms 896 KB Output is correct
9 Correct 123 ms 896 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 92 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 760 ms 1016 KB Output is correct
2 Correct 749 ms 1016 KB Output is correct
3 Correct 744 ms 1016 KB Output is correct
4 Correct 726 ms 952 KB Output is correct
5 Correct 709 ms 896 KB Output is correct
6 Correct 752 ms 896 KB Output is correct
7 Correct 545 ms 1024 KB Output is correct
8 Correct 787 ms 1016 KB Output is correct
9 Correct 802 ms 924 KB Output is correct
10 Correct 839 ms 1016 KB Output is correct
11 Correct 647 ms 924 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 0 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 566 ms 1280 KB Output is correct
33 Correct 628 ms 1408 KB Output is correct
34 Correct 685 ms 1400 KB Output is correct
35 Correct 1186 ms 1400 KB Output is correct
36 Correct 1384 ms 1336 KB Output is correct
37 Correct 792 ms 1348 KB Output is correct
38 Correct 1064 ms 1340 KB Output is correct
39 Correct 1338 ms 1340 KB Output is correct
40 Correct 770 ms 1424 KB Output is correct
41 Correct 1316 ms 1300 KB Output is correct
42 Correct 1382 ms 1400 KB Output is correct
43 Correct 712 ms 1272 KB Output is correct
44 Correct 1121 ms 1336 KB Output is correct
45 Correct 1196 ms 1356 KB Output is correct
46 Correct 1095 ms 1348 KB Output is correct
47 Correct 1135 ms 1340 KB Output is correct
48 Correct 1092 ms 1280 KB Output is correct
49 Correct 550 ms 1048 KB Output is correct
50 Correct 771 ms 1168 KB Output is correct
51 Correct 1368 ms 1228 KB Output is correct
52 Correct 754 ms 1320 KB Output is correct
53 Correct 750 ms 1340 KB Output is correct
54 Correct 1266 ms 1332 KB Output is correct
55 Correct 1481 ms 1312 KB Output is correct
56 Correct 1491 ms 1308 KB Output is correct
57 Correct 769 ms 1400 KB Output is correct
58 Correct 1253 ms 1260 KB Output is correct
59 Correct 1375 ms 1400 KB Output is correct
60 Correct 991 ms 1356 KB Output is correct
61 Correct 1334 ms 1360 KB Output is correct
62 Correct 1393 ms 1328 KB Output is correct
63 Correct 1530 ms 1260 KB Output is correct
64 Correct 1702 ms 1336 KB Output is correct
65 Correct 1534 ms 1336 KB Output is correct
66 Correct 1941 ms 1280 KB Output is correct
67 Correct 1629 ms 1244 KB Output is correct
68 Correct 2 ms 384 KB Output is correct
69 Correct 524 ms 896 KB Output is correct
70 Correct 67 ms 896 KB Output is correct
71 Correct 27 ms 896 KB Output is correct
72 Correct 123 ms 896 KB Output is correct
73 Correct 4 ms 512 KB Output is correct
74 Correct 92 ms 896 KB Output is correct
75 Correct 538 ms 1452 KB Output is correct
76 Correct 665 ms 1280 KB Output is correct
77 Correct 765 ms 1360 KB Output is correct
78 Correct 718 ms 1364 KB Output is correct
79 Correct 722 ms 1352 KB Output is correct
80 Correct 1821 ms 1324 KB Output is correct
81 Correct 1414 ms 1340 KB Output is correct
82 Correct 1620 ms 1328 KB Output is correct
83 Correct 1612 ms 1340 KB Output is correct
84 Correct 1467 ms 1336 KB Output is correct
85 Correct 745 ms 1400 KB Output is correct
86 Correct 1346 ms 1400 KB Output is correct
87 Correct 752 ms 1400 KB Output is correct
88 Correct 1049 ms 1348 KB Output is correct
89 Correct 1386 ms 1400 KB Output is correct
90 Correct 744 ms 1400 KB Output is correct
91 Correct 886 ms 1400 KB Output is correct
92 Correct 1313 ms 1280 KB Output is correct
93 Correct 1073 ms 1400 KB Output is correct
94 Correct 996 ms 1280 KB Output is correct
95 Correct 1352 ms 1280 KB Output is correct
96 Correct 1529 ms 1272 KB Output is correct
97 Correct 975 ms 1280 KB Output is correct
98 Correct 1065 ms 1328 KB Output is correct
99 Correct 952 ms 1300 KB Output is correct
100 Correct 576 ms 1148 KB Output is correct