Submission #597536

# Submission time Handle Problem Language Result Execution time Memory
597536 2022-07-16T09:09:27 Z evenvalue Werewolf (IOI18_werewolf) C++17
15 / 100
340 ms 524288 KB
#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;
}

Compilation message

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 120 ms 71492 KB Output is correct
11 Correct 125 ms 71384 KB Output is correct
12 Correct 95 ms 71376 KB Output is correct
13 Correct 93 ms 71488 KB Output is correct
14 Correct 79 ms 71372 KB Output is correct
15 Correct 112 ms 71592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 340 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 120 ms 71492 KB Output is correct
11 Correct 125 ms 71384 KB Output is correct
12 Correct 95 ms 71376 KB Output is correct
13 Correct 93 ms 71488 KB Output is correct
14 Correct 79 ms 71372 KB Output is correct
15 Correct 112 ms 71592 KB Output is correct
16 Runtime error 340 ms 524288 KB Execution killed with signal 9
17 Halted 0 ms 0 KB -