QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#92270#4512. Goose, Goose, Ducks?KHIN35 ✓4072ms47356kbC++178.9kb2023-03-30 15:04:532023-03-30 15:04:54

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 15:04:54]
  • 评测
  • 测评结果:35
  • 用时:4072ms
  • 内存:47356kb
  • [2023-03-30 15:04:53]
  • 提交

answer

# define NDEBUG

# if not KHIN_SOURCE_H

# define KHIN_SOURCE_H true

# include <cstdarg>
# include <cstdlib>
# include <type_traits>
# include <utility>
# include <climits>
# include <cassert>
# include <cctype>
# include <cstring>
# include <map>
# include <set>
# include <vector>
# include <iterator>
# include <algorithm>
# include <cstdio>

namespace khin {
  using namespace std;
  namespace main {
    inline namespace source {
      template <typename T>
        constexpr T& cmin(T& a, T const& b) { return a = min(a, b); }
      template <typename T>
        constexpr T& cmax(T& a, T const& b) { return a = max(a, b); }
      template <typename T, class Compare>
        constexpr T& cmin(T& a, T const& b, Compare const comp)
        { return a = min(a, b, comp); }
      template <typename T, class Compare>
        constexpr T& cmax(T& a, T const& b, Compare const comp)
        { return a = max(a, b, comp); }
      template <typename T>
        constexpr pair<T&, T&> cminmax(T& a, T& b)
        { return pair<T&, T&>(a, b) = minmax(T(a), T(b)); }
      template <typename T>
        constexpr pair<T, T>& cminmax(pair<T, T>& a)
        { return a = minmax(T(a.first), T(a.second)); }
      template <typename T, class Compare>
        constexpr pair<T&, T&> cminmax(T& a, T& b, Compare const comp)
        { return pair<T&, T&>(a, b) = minmax(T(a), T(b), comp); }
      template <typename T, class Compare>
        constexpr pair<T, T>& cminmax(pair<T, T>& a, Compare const comp)
        { return a = minmax(T(a.first), T(a.second), comp); }
      inline namespace io {
        class Scanner {
          FILE* const stream; char buffer[BUFSIZ];
          char *head = buffer, *tail = buffer;
          public:
          Scanner(FILE* const stream = stdin)
            : stream(stream) {}
          Scanner(char const* const filename)
            : Scanner(fopen(filename, "r")) {}
          ~Scanner() { fclose(stream); }
          private:
          void flush() {
            tail = head = buffer;
            tail += fread(buffer, sizeof(char), BUFSIZ, stream);
          }
          public:
          char getc() {
            if (head == tail) flush();
            return assert(head != tail), *head++;
          }
          template <typename T, enable_if_t<is_signed_v<T>, int> = 0>
            T get() {
              char ch;
              while (!isgraph(ch = getc()) && ch != EOF);
              int const sign(ch == '-' ? ch = getc(), -1 : +1);
              assert(isdigit(ch));
              T res(0);
              while (isdigit(ch))
                res = res * 10 + sign * (ch - '0'), ch = getc();
              return res;
            }
          template <typename T, enable_if_t<is_unsigned_v<T>, int> = 0>
            T get() {
              char ch;
              while (!isgraph(ch = getc()) && ch != EOF);
              assert(isdigit(ch));
              T res(0);
              while (isdigit(ch)) res = res * 10 + (ch - '0'), ch = getc();
              return res;
            }
          void read() {}
          template <typename T, typename... U>
            void read(T& value, U&... args)
            { value = get<T>(), read(args...); }
        };
        class Printer {
          FILE* const stream; char buffer[BUFSIZ];
          char *head = buffer, *tail = buffer;
          public:
          Printer(FILE* const stream = stdout)
            : stream(stream) {}
          Printer(char const* const filename)
            : Printer(fopen(filename, "w")) {}
          ~Printer() { flush(), fclose(stream); }
          public:
          void flush() {
            head += fwrite(head, sizeof(char), tail - head, stream);
            memmove(buffer, head, sizeof(char) * (tail - head));
            tail -= head - buffer, head -= head - buffer;
            assert(head == tail);
          }
          public:
          void putc(char const ch) {
            if (tail == buffer + BUFSIZ) flush();
            assert(tail != buffer + BUFSIZ), *tail++ = ch;
          }
          template <typename T, enable_if_t<is_unsigned_v<T>, int> = 0>
            void put(T value) {
              static char stk[CHAR_BIT * sizeof(T)], *top(stk);
              while (*top++ = value % 10 + '0', value /= 10);
              while (putc(*--top), top != stk);
            }
          void println(char const* fmt...) {
            va_list args;
            va_start(args, fmt);
            while (*fmt)
              if (*fmt == '%')
                switch (*(++fmt)++) {
                  case 'h':
                    switch (*fmt++) {
                      case 'u': put((ushort)va_arg(args, int)); break;
                      default: assert(false); break;
                    }
                    break;
                  case 'u': put(va_arg(args, uint)); break;
                  default: assert(false); break;
                }
              else putc(*fmt++);
            putc('\n');
            va_end(args);
          }
        };
      }
    }
    namespace b { void main(); }
  }
}

# endif

int main() { khin::main::b::main(); }

namespace khin::main::b {
  Scanner scanner; Printer printer;
  namespace test_case {
    constexpr uint N_max(100'000), M_max(100'000), S_max(100'000);
    class Digraph {
      struct Vertex { vector<uint> t; uint index, low, bel; bool vis; };
      uint n; Vertex v[N_max + 1]; uint index, num;
      uint siz[N_max + 2], deg[N_max + 2];
      void tarjan(uint const x) {
        static uint stk[N_max + 1], *top(stk);
        v[x].low = v[x].index = ++index, *top++ = x;
        for (uint const y : v[x].t)
          if (!v[y].index) tarjan(y), cmin(v[x].low, v[y].low);
          else if (!v[y].bel) cmin(v[x].low, v[y].index);
        if (v[x].low == v[x].index) {
          ++num;
          while (v[*--top].bel = num, *top != x);
        }
      }
      void search(uint const x) {
        if (v[x].vis) return; else v[x].vis = true;
        for (uint const y : v[x].t) search(y);
      }
      public:
      void assign(uint const n) { this->n = n; }
      void clear() {
        fill(v, v + n + 1, Vertex());
        memset(siz + 1, 0x00, sizeof(uint) * num);
        memset(deg + 1, 0x00, sizeof(uint) * num);
        num = index = n = 0;
      }
      void add(uint const s, uint const t) { v[s].t.push_back(t); }
      void tarjan() {
        for (uint i(0); i <= n; ++i) if (!v[i].index) tarjan(i);
        for (uint i(0); i <= n; ++i) ++siz[v[i].bel];
        for (uint i(0); i <= n; ++i) for (uint const j : v[i].t)
          deg[v[i].bel] += v[i].bel != v[j].bel;
      }
      uint sub(uint const x) {
        search(x);
        uint cnt(0);
        for (uint i(0); i <= n; ++i)
          cnt += v[i].vis, v[i].vis = false;
        return cnt;
      }
      uint size(uint const x) const { return siz[v[x].bel]; }
      uint calc() {
        if (sub(0) > 1) return sub(0) - 1;
        uint res(n + 1);
        for (uint i(1); i <= num; ++i)
          if (i != v[0].bel && !deg[i]) cmin(res, siz[i]);
        return res;
      }
    };
    struct Meeting { int x, y; uint c; };
    struct Statement { uint a, b; Meeting m; };
    uint N, M, S; Meeting m[M_max]; Statement s[S_max];
    vector<Statement> buc[N_max + 1]; Digraph G;
    inline bool consistent(Meeting const a, Meeting const b) {
      uint const dx(abs((int)(a.x - b.x)));
      uint const dy(abs((int)(a.y - b.y)));
      uint const dc(abs((int)(a.c - b.c)));
      return 1ul * dx * dx + 1ul * dy * dy <= 1ul * dc * dc;
    }
    void main(ushort const x) {
      scanner.read(N, M, S), G.assign(N);
      for (uint i(0); i < M; ++i)
        scanner.read(m[i].x, m[i].y, m[i].c);
      for (uint i(0); i < S; ++i) {
        scanner.read(s[i].a, s[i].b, s[i].m.x, s[i].m.y, s[i].m.c);
        buc[s[i].a].push_back(s[i]), buc[s[i].b].push_back(s[i]);
        auto const comp([] (Meeting const m, uint const t) { return m.c < t; });
        uint const find(lower_bound(m, m + M, s[i].m.c, comp) - m);
        if (find != 0 && !consistent(s[i].m, m[find - 1])) G.add(s[i].b, s[i].a);
        if (find != M && !consistent(s[i].m, m[find - 0])) G.add(s[i].b, s[i].a);
      }
      for (uint i(1); i <= N; ++i) {
        multimap<uint, Statement> map;
        for (Statement const s : buc[i]) {
          auto it(map.lower_bound(s.m.c));
          while (it != map.begin() && !consistent(prev(it)->second.m, s.m))
            G.add(0, prev(it)->second.a), map.erase(prev(it));
          while (it != map.end() && !consistent(it->second.m, s.m))
            G.add(0, it->second.a), it = map.erase(it);
          map.emplace(s.m.c, s);
        }
        buc[i].clear();
      }
      G.tarjan();
      printer.println("Case #%hu: %u", x, G.calc());
      G.clear();
    }
  }
  void main() {
    ushort const T(scanner.get<ushort>());
    for (ushort i(1); i <= T; ++i) test_case::main(i);
  }
}

詳細信息

Test #1:

score: 11
Accepted
time: 7ms
memory: 13096kb

input:

49
50 50 50
163613760 713073253 1
163613074 713073414 45509363
163613493 713073166 46300992
163613485 713073005 80138666
163613622 713073511 83426448
163613432 713072985 84610910
163613622 713073822 116617501
163613531 713073803 148444428
163613146 713073069 201070918
163613202 713073381 227533076
1...

output:

Case #1: 1
Case #2: 45
Case #3: 1
Case #4: 32
Case #5: 32
Case #6: 26
Case #7: 43
Case #8: 18
Case #9: 23
Case #10: 1
Case #11: 1
Case #12: 2
Case #13: 32
Case #14: 1
Case #15: 23
Case #16: 48
Case #17: 24
Case #18: 25
Case #19: 10
Case #20: 17
Case #21: 1
Case #22: 24
Case #23: 14
Case #24: 2
Case ...

result:

ok 49 lines

Test #2:

score: 24
Accepted
time: 4072ms
memory: 47356kb

input:

50
100000 100000 100000
-151361672 -750817089 1
-151361411 -750816686 7177
-151361458 -750817229 26692
-151361132 -750817625 39463
-151361170 -750817401 66577
-151361814 -750817632 76620
-151361394 -750817421 84901
-151360854 -750817620 89272
-151360852 -750817474 100354
-151360887 -750817072 111318...

output:

Case #1: 1
Case #2: 99995
Case #3: 1
Case #4: 66666
Case #5: 2
Case #6: 66660
Case #7: 99541
Case #8: 2
Case #9: 25
Case #10: 1
Case #11: 2
Case #12: 2
Case #13: 1
Case #14: 2
Case #15: 37519
Case #16: 99998
Case #17: 49999
Case #18: 1
Case #19: 2
Case #20: 2
Case #21: 4095
Case #22: 2
Case #23: 36
...

result:

ok 50 lines