제출 #597536

#제출 시각아이디문제언어결과실행 시간메모리
597536evenvalue늑대인간 (IOI18_werewolf)C++17
15 / 100
340 ms524288 KiB
#include "werewolf.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; class dsu { int n; std::vector<int> e; int pfind(const int x) { return (e[x] < 0 ? x : pfind(e[x])); } public: dsu() : n(0), comp(0) {} explicit dsu(const int n) : n(n), comp(n), e(n, -1) {} int comp; int find(const int x) { assert(0 <= x and x < n); return pfind(x); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return false; if (e[x] > e[y]) swap(x, y); e[x] += e[y]; e[y] = x; return true; } bool same(const int x, const int y) { return (find(x) == find(y)); } int size(const int x) { return -e[find(x)]; } std::vector<std::vector<int>> components() { std::vector<std::vector<int>> res(n); for (int x = 0; x < n; x++) { res[pfind(x)].push_back(x); } res.erase( std::remove_if(res.begin(), res.end(), [&](const std::vector<int> &v) { return v.empty(); }), res.end()); return res; } dsu &operator=(dsu other) { swap(n, other.n); swap(e, other.e); swap(comp, other.comp); return *this; } }; vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) { const int n = N, m = X.size(), q = S.size(); vector<vector<int>> g(n); for (int i = 0; i < m; i++) { g[X[i]].push_back(Y[i]); g[Y[i]].push_back(X[i]); } vector<dsu> human(n, dsu(n)), werewolf(n, dsu(n)); for (int l = n - 2; l >= 0; l--) { human[l] = human[l + 1]; for (const int y : g[l]) { if (y < l) continue; human[l].unite(l, y); } } for (int r = 1; r < n; r++) { werewolf[r] = werewolf[r - 1]; for (const int y : g[r]) { if (y > r) continue; werewolf[r].unite(r, y); } } vector<int> ans(q); for (int query = 0; query < q; query++) { const int s = S[query], e = E[query], l = L[query], r = R[query]; for (int x = l; x <= r; x++) { if (human[l].same(s, x) and werewolf[r].same(e, x)) { ans[query] = 1; } } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

werewolf.cpp: In constructor 'dsu::dsu(int)':
werewolf.cpp:37:7: warning: 'dsu::comp' will be initialized after [-Wreorder]
   37 |   int comp;
      |       ^~~~
werewolf.cpp:27:20: warning:   'std::vector<int> dsu::e' [-Wreorder]
   27 |   std::vector<int> e;
      |                    ^
werewolf.cpp:35:12: warning:   when initialized here [-Wreorder]
   35 |   explicit dsu(const int n) : n(n), comp(n), e(n, -1) {}
      |            ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...