답안 #133397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133397 2019-07-20T14:03:04 Z icypiggy 장난감 기차 (IOI17_train) C++14
100 / 100
643 ms 1840 KB
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <string.h>
#include <assert.h>

using namespace std;
const int n_max = 6000;
vector<int> backward[n_max]; // edges run in the reverse direction!
vector<int> adj[n_max];
int deg[n_max]; // this is the out degree

void init(vector<int> &u, vector<int> &v) {
    memset(deg, 0, sizeof(deg));
    for(int i=0; i<u.size(); i++) {
        backward[v[i]].push_back(u[i]);
        adj[u[i]].push_back(v[i]);
        deg[u[i]]++;
    }
}
vector<int> who_wins(vector<int> a,  vector<int> r, vector<int> u, vector<int> v) {
    init(u,v);
    bool bad = true;
    while(bad) {
        bad = false;
        vector<int> ans(a.size(), 0); // initially b always wins
        queue<int> bfs;
        for(int i=0; i<r.size(); i++) {
            if(r[i]) {
                bfs.push(i); // put in all the chargers
                ans[i] = 1;
            }
        }
        while(!bfs.empty()) {
            int next = bfs.front();
            bfs.pop();
            for(int i: backward[next]) {
                if(ans[i]==0) {
                    if(a[i]) {
                        ans[i] = true;
                        bfs.push(i);
                    } else {
                        deg[i]--;
                        if(deg[i]==0) {
                            ans[i] = true;
                            bfs.push(i);
                        }
                    }
                }
            }
        }
        for(int i=0; i<r.size(); i++) {
            if(r[i]) {
                if(a[i]) {
                    r[i] = false;
                    // you win as long as there exists an outgoing win
                    for(int j: adj[i]) {
                        if(ans[j]) {
                            r[i] = true;
                        }
                    }
                } else {
                    for(int j: adj[i]) {
                        if(ans[j]==0) {
                            r[i] = false;
                        }
                    }
                }
                if(r[i]==false) {
                    //cout << "charger " << i << " is bad\n";
                    bad = true;
                }
            }
        }
        if(!bad) {
            return ans;
        }
        memset(deg, 0, sizeof(deg));
        for(int i=0; i<u.size(); i++) {
            deg[u[i]]++;
        }
    }
    vector<int> aaa;
    assert(false);
    return aaa;
}

Compilation message

train.cpp: In function 'void init(std::vector<int>&, std::vector<int>&)':
train.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<u.size(); i++) {
                  ~^~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<r.size(); i++) {
                      ~^~~~~~~~~
train.cpp:53:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<r.size(); i++) {
                      ~^~~~~~~~~
train.cpp:80:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0; i<u.size(); i++) {
                      ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1144 KB Output is correct
2 Correct 10 ms 1144 KB Output is correct
3 Correct 9 ms 1144 KB Output is correct
4 Correct 11 ms 1144 KB Output is correct
5 Correct 10 ms 1276 KB Output is correct
6 Correct 10 ms 1144 KB Output is correct
7 Correct 8 ms 1144 KB Output is correct
8 Correct 9 ms 1144 KB Output is correct
9 Correct 8 ms 1144 KB Output is correct
10 Correct 7 ms 1144 KB Output is correct
11 Correct 6 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 2 ms 632 KB Output is correct
7 Correct 3 ms 552 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 632 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 1544 KB Output is correct
2 Correct 200 ms 1544 KB Output is correct
3 Correct 273 ms 1784 KB Output is correct
4 Correct 14 ms 1656 KB Output is correct
5 Correct 18 ms 1660 KB Output is correct
6 Correct 15 ms 1656 KB Output is correct
7 Correct 12 ms 1628 KB Output is correct
8 Correct 12 ms 1656 KB Output is correct
9 Correct 11 ms 1656 KB Output is correct
10 Correct 11 ms 1660 KB Output is correct
11 Correct 11 ms 1656 KB Output is correct
12 Correct 11 ms 1528 KB Output is correct
13 Correct 12 ms 1672 KB Output is correct
14 Correct 12 ms 1656 KB Output is correct
15 Correct 12 ms 1628 KB Output is correct
16 Correct 14 ms 1724 KB Output is correct
17 Correct 12 ms 1684 KB Output is correct
18 Correct 374 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1272 KB Output is correct
2 Correct 12 ms 1356 KB Output is correct
3 Correct 12 ms 1400 KB Output is correct
4 Correct 13 ms 1528 KB Output is correct
5 Correct 12 ms 1528 KB Output is correct
6 Correct 12 ms 1400 KB Output is correct
7 Correct 12 ms 1400 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 13 ms 1400 KB Output is correct
10 Correct 12 ms 1476 KB Output is correct
11 Correct 12 ms 1400 KB Output is correct
12 Correct 12 ms 1528 KB Output is correct
13 Correct 12 ms 1400 KB Output is correct
14 Correct 11 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1528 KB Output is correct
2 Correct 12 ms 1528 KB Output is correct
3 Correct 12 ms 1400 KB Output is correct
4 Correct 11 ms 1404 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 6 ms 1144 KB Output is correct
7 Correct 8 ms 1144 KB Output is correct
8 Correct 8 ms 1272 KB Output is correct
9 Correct 8 ms 1148 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 7 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1144 KB Output is correct
2 Correct 10 ms 1144 KB Output is correct
3 Correct 9 ms 1144 KB Output is correct
4 Correct 11 ms 1144 KB Output is correct
5 Correct 10 ms 1276 KB Output is correct
6 Correct 10 ms 1144 KB Output is correct
7 Correct 8 ms 1144 KB Output is correct
8 Correct 9 ms 1144 KB Output is correct
9 Correct 8 ms 1144 KB Output is correct
10 Correct 7 ms 1144 KB Output is correct
11 Correct 6 ms 1144 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 2 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
16 Correct 2 ms 760 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 3 ms 552 KB Output is correct
19 Correct 2 ms 632 KB Output is correct
20 Correct 2 ms 632 KB Output is correct
21 Correct 2 ms 632 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 632 KB Output is correct
24 Correct 2 ms 632 KB Output is correct
25 Correct 2 ms 632 KB Output is correct
26 Correct 2 ms 632 KB Output is correct
27 Correct 2 ms 632 KB Output is correct
28 Correct 2 ms 632 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 2 ms 632 KB Output is correct
31 Correct 2 ms 632 KB Output is correct
32 Correct 111 ms 1544 KB Output is correct
33 Correct 200 ms 1544 KB Output is correct
34 Correct 273 ms 1784 KB Output is correct
35 Correct 14 ms 1656 KB Output is correct
36 Correct 18 ms 1660 KB Output is correct
37 Correct 15 ms 1656 KB Output is correct
38 Correct 12 ms 1628 KB Output is correct
39 Correct 12 ms 1656 KB Output is correct
40 Correct 11 ms 1656 KB Output is correct
41 Correct 11 ms 1660 KB Output is correct
42 Correct 11 ms 1656 KB Output is correct
43 Correct 11 ms 1528 KB Output is correct
44 Correct 12 ms 1672 KB Output is correct
45 Correct 12 ms 1656 KB Output is correct
46 Correct 12 ms 1628 KB Output is correct
47 Correct 14 ms 1724 KB Output is correct
48 Correct 12 ms 1684 KB Output is correct
49 Correct 374 ms 1356 KB Output is correct
50 Correct 10 ms 1272 KB Output is correct
51 Correct 12 ms 1356 KB Output is correct
52 Correct 12 ms 1400 KB Output is correct
53 Correct 13 ms 1528 KB Output is correct
54 Correct 12 ms 1528 KB Output is correct
55 Correct 12 ms 1400 KB Output is correct
56 Correct 12 ms 1400 KB Output is correct
57 Correct 12 ms 1400 KB Output is correct
58 Correct 13 ms 1400 KB Output is correct
59 Correct 12 ms 1476 KB Output is correct
60 Correct 12 ms 1400 KB Output is correct
61 Correct 12 ms 1528 KB Output is correct
62 Correct 12 ms 1400 KB Output is correct
63 Correct 11 ms 1400 KB Output is correct
64 Correct 12 ms 1528 KB Output is correct
65 Correct 12 ms 1528 KB Output is correct
66 Correct 12 ms 1400 KB Output is correct
67 Correct 11 ms 1404 KB Output is correct
68 Correct 3 ms 760 KB Output is correct
69 Correct 6 ms 1144 KB Output is correct
70 Correct 8 ms 1144 KB Output is correct
71 Correct 8 ms 1272 KB Output is correct
72 Correct 8 ms 1148 KB Output is correct
73 Correct 4 ms 760 KB Output is correct
74 Correct 7 ms 1144 KB Output is correct
75 Correct 181 ms 1712 KB Output is correct
76 Correct 230 ms 1784 KB Output is correct
77 Correct 316 ms 1784 KB Output is correct
78 Correct 311 ms 1788 KB Output is correct
79 Correct 310 ms 1840 KB Output is correct
80 Correct 13 ms 1656 KB Output is correct
81 Correct 14 ms 1628 KB Output is correct
82 Correct 13 ms 1660 KB Output is correct
83 Correct 20 ms 1656 KB Output is correct
84 Correct 15 ms 1656 KB Output is correct
85 Correct 14 ms 1656 KB Output is correct
86 Correct 17 ms 1656 KB Output is correct
87 Correct 13 ms 1656 KB Output is correct
88 Correct 21 ms 1656 KB Output is correct
89 Correct 13 ms 1656 KB Output is correct
90 Correct 29 ms 1656 KB Output is correct
91 Correct 31 ms 1656 KB Output is correct
92 Correct 47 ms 1656 KB Output is correct
93 Correct 44 ms 1656 KB Output is correct
94 Correct 46 ms 1660 KB Output is correct
95 Correct 51 ms 1656 KB Output is correct
96 Correct 106 ms 1528 KB Output is correct
97 Correct 418 ms 1712 KB Output is correct
98 Correct 608 ms 1616 KB Output is correct
99 Correct 643 ms 1784 KB Output is correct
100 Correct 376 ms 1400 KB Output is correct