QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#42459#4423. AMPPZ in the times of diseaseantiravelAC ✓4588ms51216kbC++238.8kb2022-08-02 15:03:502022-08-02 15:03:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-02 15:03:54]
  • 评测
  • 测评结果:AC
  • 用时:4588ms
  • 内存:51216kb
  • [2022-08-02 15:03:50]
  • 提交

answer


#include <algorithm>
#include <bitset>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>



#include <iostream>
#include <iterator>
#include <string>
#include <tuple>
#include <utility>

namespace cm
{


class logger
{
public:
  logger(std::ostream &) {}
  logger &set_ostream(std::ostream &)
  {
    return *this;
  }
  logger &set_sep(const std::string &)
  {
    return *this;
  }
  logger &assert_push_enable()
  {
    return *this;
  }
  logger &assert_push_disable()
  {
    return *this;
  }
  logger &assert_exit()
  {
    return *this;
  }
  logger &assert_noexit()
  {
    return *this;
  }
  logger &endl()
  {
    return *this;
  }
  template <class... T>
  logger &log(T...)
  {
    return *this;
  }
  template <class T>
  logger &hint(T...)
  {
    return *this;
  }
  template <class... T>
  logger &operator()(T...)
  {
    return *this;
  }
  template <class... T>
  logger &assert_(T...)
  {
    return *this;
  }
};


namespace impl
{
logger cm_logger(std::cout);
}

} // namespace cm

// clang-format off
#define see(...)
#define asee(...)
#define cm_assert(...)
// clang-format on

// #include "/home/jack/cm/intm.hpp"
// #include "/home/jack/cm/math_util.hpp"

#include <cctype>
#include <cstdio>

namespace cm
{

template <class _Type, size_t _buf_size>
class buffer_reader
{
protected:
  FILE        *src;
  _Type *const buff;
  _Type       *buff_end;
  _Type       *buff_pos;

  void _flush()
  {
    buff_end = buff + fread(buff, sizeof(_Type), _buf_size, src);
    buff_pos = buff;
    if (buff_end == buff)
    {
      *buff_end = '\n';
      buff_end++;
    }
  }

public:
  explicit buffer_reader(FILE *_src) : src(_src), buff(new _Type[_buf_size])
  {
    _flush();
  }

  buffer_reader(const buffer_reader &) = delete;
  buffer_reader(buffer_reader &&)      = delete;
  buffer_reader &operator=(const buffer_reader &) = delete;
  buffer_reader &operator=(buffer_reader &&) = delete;

  _Type get() const
  {
    return *buff_pos;
  }
  _Type next()
  {
    _Type result = get();
    buff_pos++;
    if (buff_pos == buff_end)
      _flush();
    return result;
  }

  ~buffer_reader()
  {
    if (src != stdin)
      fclose(src);
    delete[] buff;
  }
};

template <class _BufferReader>
class scanner : protected _BufferReader
{
private:
  using _BufferReader::get;
  using _BufferReader::next;
  inline bool _is_ws(char c)
  {
    return c <= ' ';
  }
  inline bool _is_cr(char c)
  {
    return c == '\n' || c == '\r';
  }

  int _get_sign()
  {
    while (!isdigit(get()) && get() != '-')
      next();
    if (get() == '-')
      return next(), -1;
    return 1;
  }

public:
  scanner() = delete;
  using _BufferReader::_BufferReader;

  char next_char()
  {
    while (_is_ws(get()))
      next();
    return next();
  }

  char *next_token(char *s)
  {
    while (_is_ws(get()))
      next();
    while (!_is_ws(get()))
      *s++ = next();
    *s = '\0';
    return s;
  }

  char *next_line(char *s)
  {
    while (_is_ws(get()))
      next();
    while (!_is_cr(get()))
      *s++ = next();
    *s = '\0';
    return s;
  }

  template <class _Integer>
  _Integer next_integer()
  {
    _Integer sign = _get_sign();
    _Integer result(0);
    while (isdigit(get()))
      result = result * _Integer(10) + _Integer(next() - '0');
    return sign * result;
  }

  int next_int()
  {
    return next_integer<int>();
  }

  long long next_long()
  {
    return next_integer<long long>();
  }

  double next_double()
  {
    int    sign   = _get_sign();
    double result = 0;
    while (isdigit(get()))
      result = result * 10 + (next() - '0');
    if (get() == '.')
    {
      next();
      double cur_ep = 0.1;
      while (isdigit(get()))
        result += cur_ep * (next() - '0'), cur_ep *= 0.1;
    }
    return sign * result;
  }
};

} // namespace cm


namespace cm
{
using optimal_reader = buffer_reader<char, 1 << 16>;
}

#define DEFINE_SCANNER(sc, filename)                                           \
  cm::scanner<cm::optimal_reader> sc(fopen(filename, "r"));


// #include "/home/jack/cm/segment_tree.hpp"
// #include "/home/jack/cm/string.hpp"

#include <array>
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector>

namespace cm
{

template <class T>
inline bool check_min(T &a, const T &b)
{
  return b < a ? a = b, 1 : 0;
}
template <class T>
inline bool check_max(T &a, const T &b)
{
  return a < b ? a = b, 1 : 0;
}

struct once_t
{
  bool _once = true;
  bool operator()()
  {
    return _once ? (_once = false, true) : false;
  }
};

template <class T, class vt = std::vector<std::vector<T>>>
vt vec_transpose(const vt &v)
{
  size_t n = v.size();
  size_t m = v[0].size();


  vt r(m, std::vector<T>(n));
  for (size_t i = 0; i < n; i++)
    for (size_t j = 0; j < m; j++)
      r[j][i] = v[i][j];

  return r;
}

template <class value_type = int>
struct counter_t
{
private:
  value_type _value{};

public:
  value_type operator()()
  {
    return _value++;
  }

  value_type size() const
  {
    return _value;
  }

  void clear()
  {
    _value = value_type{};
  }
};

namespace impl
{
template <class T, std::size_t n0, std::size_t... n1>
struct __array
{
  using type = std::array<typename __array<T, n1...>::type, n0>;
};

template <class T, std::size_t n0>
struct __array<T, n0>
{
  using type = std::array<T, n0>;
};

} // namespace impl

template <class T, std::size_t... n0>
using array = typename impl::__array<T, n0...>::type;

#if __cplusplus >= 201402L

template <class F>
struct y_combinate_t
{
  F f;

  template <class... Args>
  decltype(auto) operator()(Args &&...args) const
  {
    return f(*this, std::forward<Args>(args)...);
  }
};

template <class F>
y_combinate_t<std::decay_t<F>> y_combinate(F &&f)
{
  return {std::forward<F>(f)};
};

auto vec_take(size_t id)
{
  return [id](const auto &v) { return v[id]; };
}

template <class F, class... T>
auto vec_map(F &&f, const std::vector<T> &...v)
{
  using mapped_t = decltype(f(std::declval<T>()...));

  std::size_t n = [](auto x, auto...) { return x; }(v.size()...);

  std::vector<mapped_t> r;
  r.reserve(n);

  cm::y_combinate([&](auto &&self, std::size_t cnt, auto... its) -> void {
    if (cnt > 0)
    {
      r.emplace_back(f((*its)...));
      self(cnt - 1, std::next(its)...);
    }
  })(n, v.begin()...);

  return r;
}

template <class F>
auto mapper(F &&f)
{
  return [f](auto v) { return vec_map(f, v); };
}

template <class T>
auto transfer(T &&v)
{
  return std::forward<T>(v);
}
template <class T, class F0, class... F1>
auto transfer(T &&v, F0 &&f0, F1 &&...f1)
{
  return transfer(f0(std::forward<T>(v)), f1...);
}

#endif

} // namespace cm

using cm::check_max;
using cm::check_min;

#define CONSTRAINT(n, a, b) constexpr auto n = a;

#include <algorithm>
#include <cstdint>
#include <limits>
#include <utility>
#include <vector>

cm::scanner<cm::optimal_reader> sc(stdin);

int main()
{
  int t = sc.next_int();
  for (int i = 0; i < t; i++)
  {
    int n = sc.next_int();
    int k = sc.next_int();

    std::vector<std::pair<int, int>> ps;
    for (int i = 0; i < n; i++)
    {
      int x = sc.next_int();
      int y = sc.next_int();
      ps.emplace_back(x, y);
    }

    auto dis = [&](int x, int y) {
      int dx = ps[x].first - ps[y].first;
      int dy = ps[x].second - ps[y].second;
      return (int64_t)dx * dx + (int64_t)dy * dy;
    };

    std::vector<int> keys{0};
    while ((int)keys.size() < k)
    {
      std::vector<int64_t> mdis;
      for (int i = 0; i < n; i++)
      {
        int64_t cur = std::numeric_limits<int64_t>::max();
        for (int k: keys)
          cm::check_min(cur, dis(k, i));
        mdis.emplace_back(cur);
      }

      int vkey
          = (int)(std::max_element(mdis.begin(), mdis.end()) - mdis.begin());
      keys.push_back(vkey);
    }

    std::vector<int> col;
    for (int i = 0; i < n; i++)
    {
      int64_t cmin_v = std::numeric_limits<int64_t>::max();
      int     cmin_i = -1;
      for (int ki = 0; ki < k; ki++)
        if (cm::check_min(cmin_v, dis(i, keys[ki])))
          cmin_i = ki;
      col.push_back(cmin_i);
    }

    for (int i = 0; i < n; i++)
      printf("%d ", col[i] + 1);
    puts("");
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4206ms
memory: 5996kb

input:

100
100000 20
270505 510725
245104 76414
131477 992924
781607 895592
562469 622976
564354 637966
980036 112090
522903 687218
113871 977855
6615 123673
13847 347618
657794 165707
420561 183995
11367 136391
507836 694877
985069 105115
774110 486921
14319 338715
774937 118145
981468 99089
803866 491315...

output:

1 11 4 3 19 19 2 8 4 5 9 10 7 5 8 2 6 9 17 2 6 10 13 3 12 1 7 16 13 19 11 10 14 12 16 3 17 7 3 14 14 9 11 1 19 13 1 20 6 20 13 20 10 13 13 18 5 1 5 13 13 17 18 9 3 7 17 16 12 17 14 10 16 12 5 10 17 6 18 15 3 2 4 6 4 9 7 12 20 6 11 19 19 13 13 3 6 12 2 13 6 1 5 1 5 13 5 7 17 6 12 14 13 12 8 20 19 13 ...

result:

ok ac (100 test cases)

Test #2:

score: 0
Accepted
time: 4588ms
memory: 51168kb

input:

5
2000000 20
128546949 27937564
245921588 62819439
245938747 62819439
245920165 62819440
245940996 62819441
245919462 62819441
245943717 62819443
245945427 62819445
245947161 62819447
245947035 62819447
245913847 62819447
245911321 62819450
245910715 62819451
245908052 62819455
245953333 62819457
24...

output:

1 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 1...

result:

ok ac (5 test cases)

Test #3:

score: 0
Accepted
time: 4467ms
memory: 51216kb

input:

5
2000000 20
938915 14534
939099 14534
938896 14534
938968 14534
939120 14534
938967 14534
939092 14534
939047 14534
939083 14534
938959 14534
938980 14534
939094 14534
939096 14534
939158 14534
939129 14534
939050 14534
939146 14534
939067 14534
938953 14534
939118 14534
939174 14534
938957 14534
9...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok ac (5 test cases)

Test #4:

score: 0
Accepted
time: 4528ms
memory: 51116kb

input:

5
1999992 20
714274 363953
4097901 6999896
4285652 7069412
672239 571422
408343 714278
4285652 6512757
995296 428566
4066535 6571329
4285652 6503633
4428508 7305200
1502570 714278
350759 714278
4078994 6999896
4285652 6566018
882958 428566
411620 714278
4085106 6999896
4285652 6530080
4142796 684433...

output:

1 20 11 14 6 9 17 16 9 2 4 6 20 9 17 6 20 9 15 4 2 18 16 2 11 11 18 20 4 3 16 17 18 14 11 18 3 3 11 14 6 4 16 9 15 16 3 14 20 14 6 9 17 3 1 16 9 9 16 14 17 11 14 2 16 15 3 4 3 16 6 4 9 16 2 14 4 18 17 18 10 11 14 10 20 1 16 4 17 9 20 4 6 3 2 9 3 9 6 4 15 4 14 16 18 11 9 20 18 18 6 4 10 3 10 14 16 18...

result:

ok ac (5 test cases)

Test #5:

score: 0
Accepted
time: 4542ms
memory: 3820kb

input:

98934
43 19
139544 85155
814904 5788
529650 268672
283948 536120
269963 210844
141436 82366
83187 749015
517204 336252
313961 432803
609446 700082
75325 746905
269976 218742
262201 982244
267097 970940
240151 822124
603197 913571
245406 817164
136898 78897
540853 274671
509382 335902
911470 765473
1...

output:

1 4 19 8 11 1 18 5 16 9 18 11 10 10 14 6 14 1 19 5 2 1 6 19 17 5 3 9 13 3 9 6 3 13 11 7 12 2 6 11 15 6 16 
1 15 17 6 2 14 4 17 6 4 19 18 3 13 1 5 7 4 7 5 15 14 5 11 13 4 1 12 18 6 5 8 7 2 10 11 5 8 13 9 14 11 8 19 6 13 5 16 18 18 4 9 10 7 16 13 16 5 4 2 12 8 11 18 5 17 10 17 11 9 9 6 5 13 1 3 
1 9 2...

result:

ok ac (98934 test cases)

Test #6:

score: 0
Accepted
time: 4377ms
memory: 51148kb

input:

5
2000000 20
797234517 492602938
798908045 502327723
792452167 502906629
798928689 489396948
788980587 490810854
799097890 494409757
802136723 493677251
798645177 497015697
788761604 495701224
794885101 501374539
806251682 495921503
794079841 483699742
797040968 499798682
804797434 501060369
8094369...

output:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

result:

ok ac (5 test cases)

Test #7:

score: 0
Accepted
time: 366ms
memory: 3740kb

input:

100000
49 3
184136 65720
77810 18746
185003 61402
190816 51862
81874 16192
199764 65637
84958 7413
196301 60803
75931 6532
76068 9903
74087 524
188023 67224
67425 5134
71213 3955
78196 9061
73745 132
84239 12547
69698 611
185262 60938
189186 65907
85093 5693
73581 15566
197267 65267
67120 5883
84736...

output:

1 3 1 1 3 1 3 1 3 3 3 1 3 3 3 3 3 3 1 1 3 3 1 3 3 3 3 3 1 3 3 1 3 3 1 2 1 3 2 3 1 1 3 1 1 3 3 3 3 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 2 3 2 2 2 2 2 3 2 2 2 2 
1 1 1 3 3 2 2 2 2 
1 1 1 1 1 1 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 
1 1 2 2 1 2 1 1 2 2 2 2 1 2 1 1 2 2 1 ...

result:

ok ac (100000 test cases)

Extra Test:

score: 0
Extra Test Passed