이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
using i32 = int;
#define len(x) (int)(x.size())
template<typename T>
using vec = vector<T>;
vector<i32> find_reachable(vector<i32> r, vector<i32> u1, vector<i32> v1, vector<i32> c) {
int n = len(r);
vec<vec<pair<int, int>>> g(n);
for (int i = 0; i < len(u1); i++) {
g[u1[i]].emplace_back(v1[i], c[i]);
g[v1[i]].emplace_back(u1[i], c[i]);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < n; i++) {
shuffle(g[i].begin(), g[i].end(), rng);
}
vec<int> key_set;
vec<vec<int>> destinations(n);
vec<bool> keys(n, false);
vec<bool> keys1(n, false);
auto clean = [&]() {
for (auto x: key_set) {
keys[x] = false;
keys1[x] = false;
vec<int>().swap(destinations[x]);
// destinations[x].clear();
}
key_set.clear();
};
vec<i32> ans(n, 1e9);
i32 cur_min = 1e9;
vec<bool> was(n, false);
auto solve = [&](int start) -> int {
clean();
queue<int> q;
auto add_key = [&](int x) -> int {
if (keys[x]) return 0;
keys[x] = true;
key_set.push_back(x);
for (auto t: destinations[x]) {
if (was[t]) {
return -1;
}
q.push(t);
}
return 0;
};
vec<bool> ok(n, false);
q.push(start);
int cnt = 0;
add_key(r[start]);
vec<int> vis;
while (!q.empty()) {
auto v = q.front();
q.pop();
vis.push_back(v);
if (ok[v]) continue;
ok[v] = true;
cnt++;
if (add_key(r[v]) == -1) {
return 1e9;
}
for (auto [u, tc]: g[v]) {
if (ok[u]) continue;
if (keys[tc]) {
if (was[u]) {
return 1e9;
}
q.push(u);
} else {
destinations[tc].push_back(u);
if (!keys1[tc]) {
keys1[tc] = true;
key_set.push_back(tc);
}
}
}
if (cnt > cur_min) {
return 1e9;
}
}
for (auto x: vis) {
ans[x] = min(ans[x], cnt);
}
return cnt;
};
vec<int> perm(n);
iota(perm.begin(), perm.end(), 0);
shuffle(perm.begin(), perm.end(), rng);
for (auto i: perm) {
solve(i);
was[i] = true;
cur_min = min(cur_min, ans[i]);
}
int min_val = *min_element(ans.begin(), ans.end());
for (int i = 0; i < n; i++) {
ans[i] = ans[i] == min_val;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
keys.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization("unroll-loops")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |