답안 #441446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441446 2021-07-05T08:10:10 Z SorahISA 열쇠 (IOI21_keys) C++17
37 / 100
122 ms 17232 KB
#include "keys.h"
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

// #define int long long
// #define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2000 + 5;

bitset<maxn> keys, vis;
vector<pii> adj[maxn]; /// (to, lock)
vector<int> wait[maxn], R;

void dfs(int now) {
    vis[now] = 1;
    if (!keys[R[now]]) {
        keys[R[now]] = 1;
        for (auto x : wait[R[now]]) dfs(x);
    }
    for (auto [to, lock] : adj[now]) {
        if (!vis[to]) {
            if (keys[lock]) dfs(to);
            else wait[lock].eb(to);
        }
    }
}

} /// end of namespace

vector<int> find_reachable(vector<int> _R, vector<int> U, vector<int> V, vector<int> C) {
    R = _R;
    int N = R.size(), M = C.size();
    
    for (int i = 0; i < M; ++i) {
        adj[U[i]].eb(V[i], C[i]), adj[V[i]].eb(U[i], C[i]);
    }
    
    vector<int> cnt(N, 0);
    for (int i = 0; i < N; ++i) {
        keys.reset(), vis.reset();
        for (int j = 0; j < N; ++j) vector<int>().swap(wait[j]);
        dfs(i), cnt[i] = vis.count();
    }
    
    int min_cnt = *min_element(ALL(cnt));
    vector<int> ans(N, 0);
    for (int i = 0; i < N; ++i) ans[i] = cnt[i] == min_cnt;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 56 ms 648 KB Output is correct
28 Correct 54 ms 660 KB Output is correct
29 Correct 52 ms 660 KB Output is correct
30 Correct 54 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 15 ms 460 KB Output is correct
35 Correct 22 ms 512 KB Output is correct
36 Correct 105 ms 588 KB Output is correct
37 Correct 84 ms 632 KB Output is correct
38 Correct 121 ms 664 KB Output is correct
39 Correct 122 ms 648 KB Output is correct
40 Correct 6 ms 460 KB Output is correct
41 Correct 36 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Runtime error 104 ms 17232 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 56 ms 648 KB Output is correct
28 Correct 54 ms 660 KB Output is correct
29 Correct 52 ms 660 KB Output is correct
30 Correct 54 ms 460 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 15 ms 460 KB Output is correct
35 Correct 22 ms 512 KB Output is correct
36 Correct 105 ms 588 KB Output is correct
37 Correct 84 ms 632 KB Output is correct
38 Correct 121 ms 664 KB Output is correct
39 Correct 122 ms 648 KB Output is correct
40 Correct 6 ms 460 KB Output is correct
41 Correct 36 ms 460 KB Output is correct
42 Runtime error 104 ms 17232 KB Execution killed with signal 11
43 Halted 0 ms 0 KB -