Submission #1074728

#TimeUsernameProblemLanguageResultExecution timeMemory
1074728shmaxKeys (IOI21_keys)C++17
0 / 100
0 ms348 KiB
#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]); } vec<int> key_set; vec<vec<int>> destinations(n); vec<bool> keys(n, false); auto clean = [&]() { for (auto x: key_set) { keys[x] = false; destinations[x].clear(); } key_set.clear(); }; vec<i32> ans(n, -1); i32 cur_min = 1e9; 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 (ans[t] > cur_min) { return -1; } q.push(t); } return 0; }; vec<bool> ok(n, false); q.push(start); int cnt = 0; add_key(r[start]); while (!q.empty()) { auto v = q.front(); q.pop(); 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 (ans[u] > cur_min) { return 1e9; } q.push(u); } else { destinations[tc].push_back(u); key_set.push_back(tc); } } if(cnt > cur_min) { return 1e9; } } return cnt; }; vec<int> perm(n); iota(perm.begin(), perm.end(), 0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); shuffle(perm.begin(), perm.end(), rng); for (auto i : perm){ ans[i] = min(ans[i],solve(i)); 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; }

Compilation message (stderr)

keys.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization("unroll-loops")
      |
#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...