답안 #160375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160375 2019-10-27T08:23:51 Z rama_pang 장난감 기차 (IOI17_train) C++14
100 / 100
880 ms 1884 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;

const int AREZOU = 1;
const int BORZOU = 0;
const int CHARGING_STATION = 1;
const int CHARGING_SET = 1;
const int VISITED = 1;

int N, M;
vector<int> station, owner;
vector<vector<int>> G, G_inverse;

vector<int> out_degree;
vector<int> visited;
vector<int> charging_set;
vector<int> new_charging_set;

void initialize_charging_set() {
    visited.assign(N, !VISITED);
    out_degree.assign(N, 0);
    charging_set.assign(N, !CHARGING_SET);

    queue<int> q;
    for (int i = 0; i < N; i++) 
        if (station[i] == CHARGING_STATION && new_charging_set[i] == CHARGING_SET) 
            q.push(i), visited[i] = VISITED;
    
    while (!q.empty()) {
        int u = q.front(); q.pop();
        charging_set[u] = CHARGING_SET;
        for (auto v : G_inverse[u]) {
            if (visited[v] == VISITED) continue;

            switch (owner[v]) {
            case AREZOU:
                if (visited[v] == !VISITED) {  
                    visited[v] = VISITED;
                    q.push(v);
                }
                break;
            case BORZOU:
                out_degree[v]++;
                if (out_degree[v] == G[v].size() && visited[v] == !VISITED) {
                    visited[v] = VISITED;
                    q.push(v);
                }
                break;
            }
        }
    }

}

vector<int> who_wins(vector<int> owner_, vector<int> charge_, vector<int> u_, vector<int> v_) {
	owner = owner_, station = charge_;
    N = owner.size(), M = u_.size();
    G.resize(N), G_inverse.resize(N);
    new_charging_set.resize(N, CHARGING_SET);

    for (int i = 0; i < M; i++) {
        G[u_[i]].push_back(v_[i]);
        G_inverse[v_[i]].push_back(u_[i]);
    }

    while (charging_set != new_charging_set) {
        initialize_charging_set();

        for (int i = 0; i < N; i++) {
            switch (owner[i]) {
            case AREZOU:
                new_charging_set[i] = !CHARGING_SET;
                for (auto v : G[i]) 
                    if (charging_set[v] == CHARGING_SET) 
                        new_charging_set[i] = CHARGING_SET;
                    
                break;
            
            case BORZOU:
                new_charging_set[i] = CHARGING_SET;
                for (auto v : G[i]) 
                    if (charging_set[v] == !CHARGING_SET) 
                        new_charging_set[i] = !CHARGING_SET;
                    
                break;
            }
        }

    }

    vector<int> res(N);
    for (int i = 0; i < N; i++) 
        res[i] = (charging_set[i] == CHARGING_SET);

    return res;
}

Compilation message

train.cpp: In function 'void initialize_charging_set()':
train.cpp:45:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (out_degree[v] == G[v].size() && visited[v] == !VISITED) {
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1272 KB Output is correct
2 Correct 11 ms 1276 KB Output is correct
3 Correct 11 ms 1276 KB Output is correct
4 Correct 12 ms 1272 KB Output is correct
5 Correct 10 ms 1272 KB Output is correct
6 Correct 11 ms 1272 KB Output is correct
7 Correct 10 ms 1272 KB Output is correct
8 Correct 11 ms 1272 KB Output is correct
9 Correct 9 ms 1272 KB Output is correct
10 Correct 8 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 8 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 1784 KB Output is correct
2 Correct 232 ms 1884 KB Output is correct
3 Correct 356 ms 1784 KB Output is correct
4 Correct 13 ms 1692 KB Output is correct
5 Correct 19 ms 1656 KB Output is correct
6 Correct 17 ms 1656 KB Output is correct
7 Correct 12 ms 1656 KB Output is correct
8 Correct 12 ms 1784 KB Output is correct
9 Correct 11 ms 1656 KB Output is correct
10 Correct 12 ms 1656 KB Output is correct
11 Correct 12 ms 1656 KB Output is correct
12 Correct 11 ms 1528 KB Output is correct
13 Correct 21 ms 1784 KB Output is correct
14 Correct 12 ms 1784 KB Output is correct
15 Correct 12 ms 1756 KB Output is correct
16 Correct 12 ms 1784 KB Output is correct
17 Correct 13 ms 1784 KB Output is correct
18 Correct 470 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1524 KB Output is correct
2 Correct 12 ms 1528 KB Output is correct
3 Correct 12 ms 1656 KB Output is correct
4 Correct 14 ms 1656 KB Output is correct
5 Correct 13 ms 1656 KB Output is correct
6 Correct 13 ms 1656 KB Output is correct
7 Correct 13 ms 1784 KB Output is correct
8 Correct 12 ms 1656 KB Output is correct
9 Correct 13 ms 1628 KB Output is correct
10 Correct 13 ms 1656 KB Output is correct
11 Correct 13 ms 1784 KB Output is correct
12 Correct 14 ms 1784 KB Output is correct
13 Correct 12 ms 1656 KB Output is correct
14 Correct 12 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1788 KB Output is correct
2 Correct 13 ms 1784 KB Output is correct
3 Correct 12 ms 1656 KB Output is correct
4 Correct 12 ms 1528 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 7 ms 1148 KB Output is correct
7 Correct 7 ms 1016 KB Output is correct
8 Correct 8 ms 1144 KB Output is correct
9 Correct 8 ms 1144 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 7 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1272 KB Output is correct
2 Correct 11 ms 1276 KB Output is correct
3 Correct 11 ms 1276 KB Output is correct
4 Correct 12 ms 1272 KB Output is correct
5 Correct 10 ms 1272 KB Output is correct
6 Correct 11 ms 1272 KB Output is correct
7 Correct 10 ms 1272 KB Output is correct
8 Correct 11 ms 1272 KB Output is correct
9 Correct 9 ms 1272 KB Output is correct
10 Correct 8 ms 1272 KB Output is correct
11 Correct 6 ms 1272 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 8 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 121 ms 1784 KB Output is correct
33 Correct 232 ms 1884 KB Output is correct
34 Correct 356 ms 1784 KB Output is correct
35 Correct 13 ms 1692 KB Output is correct
36 Correct 19 ms 1656 KB Output is correct
37 Correct 17 ms 1656 KB Output is correct
38 Correct 12 ms 1656 KB Output is correct
39 Correct 12 ms 1784 KB Output is correct
40 Correct 11 ms 1656 KB Output is correct
41 Correct 12 ms 1656 KB Output is correct
42 Correct 12 ms 1656 KB Output is correct
43 Correct 11 ms 1528 KB Output is correct
44 Correct 21 ms 1784 KB Output is correct
45 Correct 12 ms 1784 KB Output is correct
46 Correct 12 ms 1756 KB Output is correct
47 Correct 12 ms 1784 KB Output is correct
48 Correct 13 ms 1784 KB Output is correct
49 Correct 470 ms 1400 KB Output is correct
50 Correct 11 ms 1524 KB Output is correct
51 Correct 12 ms 1528 KB Output is correct
52 Correct 12 ms 1656 KB Output is correct
53 Correct 14 ms 1656 KB Output is correct
54 Correct 13 ms 1656 KB Output is correct
55 Correct 13 ms 1656 KB Output is correct
56 Correct 13 ms 1784 KB Output is correct
57 Correct 12 ms 1656 KB Output is correct
58 Correct 13 ms 1628 KB Output is correct
59 Correct 13 ms 1656 KB Output is correct
60 Correct 13 ms 1784 KB Output is correct
61 Correct 14 ms 1784 KB Output is correct
62 Correct 12 ms 1656 KB Output is correct
63 Correct 12 ms 1656 KB Output is correct
64 Correct 13 ms 1788 KB Output is correct
65 Correct 13 ms 1784 KB Output is correct
66 Correct 12 ms 1656 KB Output is correct
67 Correct 12 ms 1528 KB Output is correct
68 Correct 3 ms 376 KB Output is correct
69 Correct 7 ms 1148 KB Output is correct
70 Correct 7 ms 1016 KB Output is correct
71 Correct 8 ms 1144 KB Output is correct
72 Correct 8 ms 1144 KB Output is correct
73 Correct 4 ms 504 KB Output is correct
74 Correct 7 ms 1016 KB Output is correct
75 Correct 187 ms 1756 KB Output is correct
76 Correct 297 ms 1784 KB Output is correct
77 Correct 406 ms 1784 KB Output is correct
78 Correct 405 ms 1772 KB Output is correct
79 Correct 405 ms 1784 KB Output is correct
80 Correct 13 ms 1784 KB Output is correct
81 Correct 14 ms 1656 KB Output is correct
82 Correct 14 ms 1656 KB Output is correct
83 Correct 17 ms 1784 KB Output is correct
84 Correct 16 ms 1656 KB Output is correct
85 Correct 15 ms 1656 KB Output is correct
86 Correct 19 ms 1772 KB Output is correct
87 Correct 13 ms 1656 KB Output is correct
88 Correct 26 ms 1784 KB Output is correct
89 Correct 13 ms 1784 KB Output is correct
90 Correct 36 ms 1784 KB Output is correct
91 Correct 41 ms 1656 KB Output is correct
92 Correct 64 ms 1784 KB Output is correct
93 Correct 60 ms 1656 KB Output is correct
94 Correct 62 ms 1784 KB Output is correct
95 Correct 69 ms 1656 KB Output is correct
96 Correct 144 ms 1668 KB Output is correct
97 Correct 514 ms 1656 KB Output is correct
98 Correct 845 ms 1656 KB Output is correct
99 Correct 880 ms 1680 KB Output is correct
100 Correct 478 ms 1400 KB Output is correct