Submission #441446

#TimeUsernameProblemLanguageResultExecution timeMemory
441446SorahISAKeys (IOI21_keys)C++17
37 / 100
122 ms17232 KiB
#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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...