QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865905#8830. Breaking BadXiaohubaTL 1ms7768kbC++237.2kb2025-01-22 08:22:572025-01-22 08:22:58

Judging History

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

  • [2025-01-22 08:22:58]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7768kb
  • [2025-01-22 08:22:57]
  • 提交

answer

#pragma GCC optimize("Ofast")

#include <vector>

#pragma GCC target("avx2")

#ifndef M_MODINT_H
#define M_MODINT_H

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#if __cplusplus < 201700L
#pragma GCC diagnostic ignored "-Wc++17-extensions"
#warning "Some features may not be available under c++17."
#endif

#define _static_helper __attribute__((always_inline)) constexpr inline static
#define _set_op(tp, op, attr)                                                  \
  attr tp operator op(const tp &rhs) const {                                   \
    tp lhs = *this;                                                            \
    return lhs op## = rhs;                                                     \
  }

// === BEGIN Modint library ===

namespace Moeebius {

template <std::uint32_t mod> class Modint {
  using u16 = std::uint16_t;
  using i32 = std::int32_t;
  using u32 = std::uint32_t;

  u16 _v;
  _static_helper u16 __get_inv_r(u16 x) {
    u16 y = x;
    y *= 2u - x * y, y *= 2u - x * y, y *= 2u - x * y;
    return y;
  }
  _static_helper u16 __shrk(u16 x) { return std::min<u16>(x, x - mod); }
  _static_helper u16 __shrk2(u16 x) { return std::min<u16>(x, x - 2u * mod); }
  _static_helper u16 __dilt2(u16 x) { return std::min<u16>(x, x + 2u * mod); }
  _static_helper u16 __reduce(u32 x) {
    return (x + u32(u16(u16(x) * -mod_inv)) * mod) >> 16;
  }

  constexpr static inline u16 r2 = (1ull << 32) % mod,
                              mod_inv = __get_inv_r(mod);
  static_assert(mod && (mod < (1 << 14)) && (mod & 1) &&
                ((mod_inv * mod) & UINT16_MAX) == 1u &&
                __reduce(r2) == (1 << 16) % mod);

public:
  constexpr Modint() : _v(0) {}
  constexpr Modint(u16 v) : _v(__reduce(u32(v) * r2)) {}
  constexpr Modint operator-() const { return Modint() - *this; }
  constexpr Modint &operator+=(Modint rhs) {
    return _v = __shrk2(_v + rhs._v), *this;
  }
  constexpr Modint &operator-=(Modint rhs) {
    return _v = __dilt2(_v - rhs._v), *this;
  }
  constexpr Modint &operator*=(Modint rhs) {
    return _v = __reduce(u32(_v) * rhs._v), *this;
  }
  constexpr Modint pow(u32 y) const {
    Modint ans = 1, x = *this;
    while (y) {
      if (y & 1)
        ans *= x;
      x *= x, y >>= 1;
    }
    return ans;
  }
  constexpr Modint inv() const { return this->pow(mod - 2); }
  constexpr u16 val() const { return __shrk(__reduce(_v)); }
  constexpr Modint &operator/=(Modint rhs) { return (*this) *= rhs.inv(); }
  constexpr explicit operator bool() const { return __shrk(_v); }
  constexpr bool operator==(const Modint &rhs) const {
    return __shrk(_v) == __shrk(rhs._v);
  }
  constexpr bool operator!=(const Modint &rhs) const {
    return __shrk(_v) != __shrk(rhs._v);
  }
  _set_op(Modint, +, constexpr);
  _set_op(Modint, -, constexpr);
  _set_op(Modint, *, constexpr);
  _set_op(Modint, /, constexpr);
};
} // namespace Moeebius

// === END Modint library ===

#undef _static_helper
#undef _set_op

#pragma GCC diagnostic pop

#endif

#include <bits/stdc++.h>
// #include <moeebius/modint.hpp>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
#endif

#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define ssz(x) (signed((x).size()))
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i) // NOLINT
#define ForDown(i, j, k)                                                       \
  for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i) // NOLINT
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
CONSTEXPR_FUNC il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c - '0'); c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on

// File head end

namespace {
constexpr int mod = 16001, g = 3;
using Z = Moeebius::Modint<mod>;
int n, a[1000][1000];
Z b[1000][1000], c[500][500], inv[mod + 5], pw[17], piw[17], ans[5];
mt19937 rnd(random_device{}());
__attribute__((noinline)) Z det() {
  bool f = 1;
  int len = min(n, 500);
  For(i, 0, len - 1) {
    int p = i;
    while (p < len && !c[p][i])
      p++;
    if (p == len)
      return {};
    if (p != i)
      swap(c[p], c[i]), f ^= 1;
    Z iv = inv[c[i][i].val()];
    For(j, 0, len - 1) if (j != i) {
      Z mul = c[j][i] * iv;
#pragma GCC unroll(8)
#pragma GCC ivdep
      For(k, 0, len - 1) c[j][k] -= c[i][k] * mul;
    }
  }
  Z ans = f ? 1 : (mod - 1);
  For(i, 0, len - 1) ans *= c[i][i];
  return ans;
}
void Main() {
  read(n);
  For(i, 0, n - 1) For(j, 0, n - 1) read(a[i][j]), b[i][j] = int(rnd() % mod);
  inv[1] = 1;
  For(i, 2, mod - 1) inv[i] = inv[mod % i] * Z(mod - mod / i);
  Z wn = Z(g).pow((mod - 1) / 5), iwn = wn.inv();
  pw[0] = piw[0] = 1;
  For(i, 1, 16) pw[i] = pw[i - 1] * wn, piw[i] = piw[i - 1] * iwn;
  if (n <= 550) {
    For(o, 0, 4) {
      For(i, 0, n - 1) For(j, 0, n - 1) c[i][j] = b[i][j] * pw[a[i][j] * o];
      Z val = det();
      For(i, 0, 4) ans[i] += val * piw[i * o];
    }
  } else {
    For(_, 1, 5) {
      shuffle(a, a + n, rnd);
      For(i, 0, n - 1) shuffle(a[i], a[i] + n, rnd);
      For(o, 0, 4) {
        For(i, 0, 499) For(j, 0, 499) c[i][j] = b[i][j] * pw[a[i][j] * o];
        Z val = det();
        For(i, 0, 4) ans[i] += val * piw[i * o];
      }
    }
  }
  For(i, 0, 4) putchar((ans[i]) ? 'Y' : 'N');
}
} // namespace

signed main() { return Main(), 0; }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5844kb

input:

2
0 4
4 0

output:

YNNYN

result:

ok "YNNYN"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

2
1 1
1 1

output:

NNYNN

result:

ok "NNYNN"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

4
0 0 1 0
0 1 0 1
0 0 0 0
1 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #4:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

4
0 0 0 1
0 1 0 1
1 0 0 0
0 1 0 0

output:

YYYYN

result:

ok "YYYYN"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5716kb

input:

10
1 4 2 0 0 2 0 1 3 3
0 3 1 4 4 1 4 0 2 2
1 4 2 0 0 2 0 1 0 3
0 3 1 4 4 1 4 0 2 2
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
4 2 0 3 3 0 3 4 1 1
2 0 3 1 1 3 1 2 4 4
1 4 2 0 0 2 0 1 3 3
3 1 4 2 2 4 2 3 0 0

output:

NYNNY

result:

ok "NYNNY"

Test #6:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

10
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
3 3 3 0 2 3 0 3 2 4
4 4 4 1 3 4 1 4 3 0
2 2 2 4 1 2 4 2 1 3
2 2 2 4 1 3 4 2 1 3
4 4 4 1 3 4 1 4 3 0
3 3 3 0 2 3 0 3 2 4
2 2 2 4 1 2 4 2 1 3
4 4 4 1 3 4 1 1 3 0

output:

YYYNY

result:

ok "YYYNY"

Test #7:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

10
1 2 0 4 2 3 4 0 2 3
0 1 4 3 1 2 3 4 1 2
4 0 3 2 0 1 2 3 0 1
1 2 0 4 2 3 4 0 2 3
3 4 2 1 4 0 1 2 4 0
0 1 4 3 1 2 3 4 1 2
2 3 1 0 3 4 0 1 3 4
3 1 1 1 4 0 1 2 4 0
1 2 0 4 2 3 4 0 2 3
1 3 0 4 2 3 4 0 2 3

output:

NYYYY

result:

ok "NYYYY"

Test #8:

score: 0
Accepted
time: 0ms
memory: 7760kb

input:

10
3 4 0 3 2 2 0 4 0 2
0 1 2 0 4 4 2 1 2 4
2 3 4 2 1 1 4 3 4 1
0 1 2 0 4 4 2 1 2 4
0 1 2 0 4 4 2 1 2 4
0 1 2 0 4 4 2 1 2 4
3 4 0 3 2 2 0 4 0 2
0 1 2 0 4 4 2 1 2 4
3 4 0 3 2 2 0 4 0 2
0 1 2 0 4 4 2 1 2 4

output:

NYNNN

result:

ok "NYNNN"

Test #9:

score: 0
Accepted
time: 0ms
memory: 7764kb

input:

10
4 1 3 1 2 0 3 2 4 4
0 2 4 2 3 1 4 3 0 0
1 1 1 1 2 0 3 2 4 1
2 4 1 4 0 3 1 0 2 2
1 3 0 3 4 2 0 4 1 1
2 4 1 4 0 3 1 0 2 2
2 4 1 4 0 3 1 0 2 2
0 2 4 2 3 1 4 3 0 0
3 0 2 1 1 4 2 1 3 3
4 1 3 1 2 0 3 2 4 4

output:

YYYYY

result:

ok "YYYYY"

Test #10:

score: 0
Accepted
time: 0ms
memory: 5720kb

input:

10
1 2 0 2 4 2 3 1 2 1
4 0 3 0 2 0 1 4 0 4
0 1 4 1 3 1 2 0 1 0
0 1 4 1 3 1 2 0 1 0
3 4 2 4 1 4 0 3 4 3
4 0 3 0 2 0 1 4 0 4
0 1 4 1 3 1 2 0 1 0
0 1 4 1 3 1 2 0 1 0
3 4 2 4 1 4 0 3 4 3
0 1 4 1 3 1 2 0 1 0

output:

NNNYN

result:

ok "NNNYN"

Test #11:

score: 0
Accepted
time: 0ms
memory: 7764kb

input:

10
1 4 1 2 1 3 3 2 1 2
0 3 0 1 0 2 2 1 0 1
0 4 0 3 0 2 2 1 0 1
1 4 1 2 1 3 3 2 1 2
4 2 4 0 4 1 1 0 4 0
1 1 1 4 1 0 3 2 1 2
0 0 0 1 0 2 2 1 0 1
2 0 2 3 2 4 4 3 2 3
2 0 2 3 2 4 4 3 2 3
2 0 2 3 2 4 4 3 2 3

output:

YYYYY

result:

ok "YYYYY"

Test #12:

score: 0
Accepted
time: 0ms
memory: 5716kb

input:

10
1 2 0 1 4 0 1 2 2 2
1 2 0 1 4 3 1 2 2 2
0 1 4 0 3 1 0 1 1 1
1 2 0 1 4 3 1 2 2 2
3 4 2 3 1 4 3 4 4 4
0 1 4 0 3 1 0 1 1 1
4 0 3 4 2 0 4 0 0 0
3 4 2 3 1 4 3 4 4 4
4 0 3 4 2 0 4 0 0 0
0 1 4 0 3 1 0 1 1 1

output:

YNYNY

result:

ok "YNYNY"

Test #13:

score: 0
Accepted
time: 1ms
memory: 5716kb

input:

10
1 3 0 0 2 1 3 4 3 3
3 3 0 0 4 1 3 4 3 3
1 1 3 3 2 4 1 2 1 1
2 4 1 1 3 2 4 0 4 4
4 1 3 3 0 4 1 2 1 1
2 4 1 1 3 2 4 0 4 4
0 2 4 4 1 0 2 3 2 2
3 0 2 2 4 3 0 1 0 0
3 0 2 2 4 3 0 1 0 0
4 2 4 4 1 0 2 3 2 2

output:

YYYNY

result:

ok "YYYNY"

Test #14:

score: 0
Accepted
time: 0ms
memory: 7768kb

input:

10
2 0 3 1 3 0 0 0 4 1
1 4 2 0 2 4 4 4 3 0
2 0 3 1 3 0 0 0 4 1
1 4 2 0 2 4 4 4 3 0
1 4 2 0 2 4 4 4 3 0
3 3 4 2 4 1 1 1 0 2
3 1 4 2 4 1 1 1 0 2
4 2 0 3 0 2 2 2 1 3
3 1 4 2 4 1 1 1 0 2
1 4 2 0 2 4 4 4 3 0

output:

YNYNN

result:

ok "YNYNN"

Test #15:

score: -100
Time Limit Exceeded

input:

1000
3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...

output:

YYYYY

result: