結果

問題 No.2345 max(l,r)
ユーザー そすうぽよそすうぽよ
提出日時 2023-06-09 22:50:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 7,365 bytes
コンパイル時間 2,795 ms
コンパイル使用メモリ 227,108 KB
実行使用メモリ 15,320 KB
最終ジャッジ日時 2024-06-10 13:59:48
合計ジャッジ時間 9,205 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,400 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 55 ms
6,400 KB
testcase_07 AC 55 ms
6,528 KB
testcase_08 AC 56 ms
6,272 KB
testcase_09 AC 57 ms
6,400 KB
testcase_10 AC 59 ms
6,400 KB
testcase_11 AC 58 ms
6,400 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 59 ms
15,252 KB
testcase_23 AC 61 ms
15,320 KB
testcase_24 AC 20 ms
8,960 KB
testcase_25 AC 24 ms
6,400 KB
testcase_26 AC 24 ms
6,528 KB
testcase_27 AC 22 ms
6,528 KB
testcase_28 AC 12 ms
7,296 KB
testcase_29 AC 19 ms
7,296 KB
testcase_30 AC 10 ms
6,656 KB
testcase_31 AC 25 ms
7,808 KB
testcase_32 AC 13 ms
6,912 KB
testcase_33 AC 16 ms
7,040 KB
testcase_34 AC 5 ms
6,528 KB
testcase_35 AC 8 ms
6,784 KB
testcase_36 AC 10 ms
6,784 KB
testcase_37 AC 13 ms
6,912 KB
testcase_38 AC 31 ms
7,936 KB
testcase_39 AC 50 ms
8,704 KB
testcase_40 AC 40 ms
8,064 KB
testcase_41 AC 30 ms
7,936 KB
testcase_42 AC 36 ms
8,064 KB
testcase_43 AC 32 ms
7,936 KB
testcase_44 AC 50 ms
8,576 KB
testcase_45 AC 70 ms
11,540 KB
testcase_46 AC 65 ms
10,368 KB
testcase_47 AC 38 ms
7,936 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 RE -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 330 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <variant>

#define rep2(i, k, n) for (i64 i = (i64)(k); i < (i64)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) begin(x), end(x)
#ifdef ENV_LOCAL
#define dump \
  if (1) cerr
#else
#define dump \
  if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

/*
 * harudake::modint
 *
 * Copyright (c) 2021 prime number
 *
 * This software is released under the MIT license.
 * see https://opensource.org/licenses/MIT
 *
 */
namespace harudake {

template <typename base_t, base_t MOD>
class static_modint;

using modint_1000000007 = static_modint<uint64_t, 1'000'000'007>;
using modint_998244353 = static_modint<uint64_t, 998'244'353>;

template <typename base_t, base_t MOD>
static_modint<base_t, MOD> add(const static_modint<base_t, MOD> lhs,
                               const static_modint<base_t, MOD> rhs) {
  base_t tmp = lhs.val + rhs.val;
  if (tmp >= MOD) tmp -= MOD;
  return static_modint<base_t, MOD>::make_raw(tmp);
}

template <typename base_t, base_t MOD>
static_modint<base_t, MOD> sub(const static_modint<base_t, MOD> lhs,
                               const static_modint<base_t, MOD> rhs) {
  base_t tmp = lhs.val + MOD - rhs.val;
  if (tmp >= MOD) tmp -= MOD;
  return static_modint<base_t, MOD>::make_raw(tmp);
}

template <typename base_t, base_t MOD>
static_modint<base_t, MOD> mul(const static_modint<base_t, MOD> lhs,
                               const static_modint<base_t, MOD> rhs) {
  base_t tmp = lhs.val * rhs.val;
  tmp %= MOD;
  return static_modint<base_t, MOD>::make_raw(tmp);
}

// data types must be signed integer
inline int64_t inv(const int64_t a, const int64_t p) {
  return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
};

template <typename base_t, base_t MOD>
static_modint<base_t, MOD> div(const static_modint<base_t, MOD> lhs,
                               const static_modint<base_t, MOD> rhs) {
  base_t tmp = lhs.val * inv(rhs.val, MOD);
  tmp %= MOD;
  return static_modint<base_t, MOD>::make_raw(tmp);
}

template <typename base_t, base_t MOD>
static_modint<base_t, MOD> pow(const static_modint<base_t, MOD> base,
                               const uint64_t index) {
  if (index == 0) return static_modint<base_t, MOD>{1};
  if (index % 2 == 1) {
    return pow(base, index - 1) * base;
  } else {
    auto half = pow(base, index / 2);
    return half * half;
  }
}

template <typename base_t, base_t MOD>
class static_modint {
  using modint = static_modint;

 public:
  static constexpr base_t mod = MOD;
  static_modint() : val(0) {}
  static_modint(const base_t x) : val(x % MOD) {}
  static_modint(const modint&) = default;
  modint& operator=(const modint&) = default;
  modint& operator=(const base_t x) {
    val = x % MOD;
    return *this;
  }
  modint operator-() const { return val == 0 ? 0 : MOD - val; }
  explicit operator base_t() const { return val; }
  base_t get() const { return val; }
  constexpr base_t get_mod() const { return mod; }
  static modint make_raw(const base_t raw) {
    modint res;
    res.val = raw;
    return res;
  }

 private:
  friend modint add<base_t, MOD>(const modint, const modint);
  friend modint sub<base_t, MOD>(const modint, const modint);
  friend modint mul<base_t, MOD>(const modint, const modint);
  friend modint div<base_t, MOD>(const modint, const modint);
  base_t val;
};

template <typename base_t, base_t MOD>
static_modint<base_t, MOD> operator+(const static_modint<base_t, MOD> lhs,
                                     const static_modint<base_t, MOD> rhs) {
  return add(lhs, rhs);
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD> operator-(const static_modint<base_t, MOD> lhs,
                                     const static_modint<base_t, MOD> rhs) {
  return sub(lhs, rhs);
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD> operator*(const static_modint<base_t, MOD> lhs,
                                     const static_modint<base_t, MOD> rhs) {
  return mul(lhs, rhs);
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD> operator/(const static_modint<base_t, MOD> lhs,
                                     const static_modint<base_t, MOD> rhs) {
  return div(lhs, rhs);
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD> operator^(const static_modint<base_t, MOD> lhs,
                                     const uint64_t rhs) {
  return pow(lhs, rhs);
}

template <typename base_t, base_t MOD>
static_modint<base_t, MOD>& operator+=(static_modint<base_t, MOD>& lhs,
                                       const static_modint<base_t, MOD> rhs) {
  return lhs = lhs + rhs;
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD>& operator-=(static_modint<base_t, MOD>& lhs,
                                       const static_modint<base_t, MOD> rhs) {
  return lhs = lhs - rhs;
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD>& operator*=(static_modint<base_t, MOD>& lhs,
                                       const static_modint<base_t, MOD> rhs) {
  return lhs = lhs * rhs;
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD>& operator/=(static_modint<base_t, MOD>& lhs,
                                       const static_modint<base_t, MOD> rhs) {
  return lhs = lhs / rhs;
}
template <typename base_t, base_t MOD>
static_modint<base_t, MOD>& operator^=(static_modint<base_t, MOD>& lhs,
                                       const uint64_t rhs) {
  return lhs = lhs ^ rhs;
}

}  // namespace harudake
using namespace harudake;
using modint = modint_998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 MAX_F = 200001;
  vector<modint> fact(MAX_F);
  fact[0] = modint(1);
  rep(i, MAX_F - 1) fact[i + 1] = fact[i] * modint(i + 1);
  vector<modint> invf(MAX_F);
  invf.back() = modint(1) / fact.back();
  rep(ri, MAX_F - 1) {
    i64 i = MAX_F - ri - 1;
    invf[i - 1] = invf[i] * modint(i);
  }
  auto comb = [&](i64 n, i64 k) { return fact[n] * invf[k] * invf[n - k]; };
  i64 t;
  cin >> t;
  rep(tnum, t) {
    i64 n, m;
    cin >> n >> m;
    vi64 a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    map<i64, i64> hist;
    rep(i, n) { ++hist[a[i]]; }
    vector<pair<i64, i64>> vp;
    for (auto&& [x, y] : hist) {
      vp.emplace_back(x, y);
    }
    reverse(all(vp));
    map<pair<i64, i64>, modint> dp;
    dp[make_pair(0, 0)] = modint(1);
    i64 total = 0;
    for (auto&& [x, y] : vp) {
      map<pair<i64, i64>, modint> nxt;
      for (auto&& [key, cnt] : dp) {
        auto [left, num] = key;
        i64 right = total - left;
        rep(p, y + 1) {
          i64 q = y - p;
          i64 llr = max(left, n - left - p);
          i64 rlr = max(right, n - right - q);
          if (p > 0 && llr != x) continue;
          if (q > 0 && rlr != x) continue;
          i64 new_num = num + 1;
          if (p > 0 && q > 0) ++new_num;
          nxt[make_pair(left + p, new_num)] += cnt * comb(y, p);
        }
      }
      swap(dp, nxt);
      total += y;
    }
    modint ans = 0;
    for (auto&& [key, cnt] : dp) {
      auto [left, num] = key;
      ans += cnt * comb(m, num);
    }
    ans /= modint(2);
    cout << ans.get() << endl;
  }
  return 0;
}
0