結果

問題 No.2164 Equal Balls
ユーザー KudeKude
提出日時 2022-12-15 13:04:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 771 ms / 5,000 ms
コード長 2,315 bytes
コンパイル時間 3,015 ms
コンパイル使用メモリ 240,988 KB
実行使用メモリ 9,956 KB
最終ジャッジ日時 2023-08-08 22:48:06
合計ジャッジ時間 16,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 34 ms
4,512 KB
testcase_12 AC 12 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 33 ms
4,484 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 20 ms
4,436 KB
testcase_19 AC 39 ms
4,764 KB
testcase_20 AC 14 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 22 ms
4,380 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 20 ms
4,376 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 15 ms
4,376 KB
testcase_31 AC 27 ms
4,384 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 15 ms
4,376 KB
testcase_34 AC 18 ms
4,380 KB
testcase_35 AC 5 ms
4,380 KB
testcase_36 AC 32 ms
4,652 KB
testcase_37 AC 32 ms
4,652 KB
testcase_38 AC 753 ms
9,884 KB
testcase_39 AC 753 ms
9,808 KB
testcase_40 AC 752 ms
9,892 KB
testcase_41 AC 752 ms
9,804 KB
testcase_42 AC 757 ms
9,896 KB
testcase_43 AC 752 ms
9,804 KB
testcase_44 AC 752 ms
9,956 KB
testcase_45 AC 752 ms
9,904 KB
testcase_46 AC 751 ms
9,916 KB
testcase_47 AC 752 ms
9,888 KB
testcase_48 AC 771 ms
9,188 KB
testcase_49 AC 626 ms
4,644 KB
testcase_50 AC 626 ms
4,640 KB
testcase_51 AC 626 ms
4,588 KB
testcase_52 AC 626 ms
4,640 KB
testcase_53 AC 626 ms
4,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

constexpr int FACT_SIZE = 10000;
mint Fact[FACT_SIZE + 1];
mint iFact[FACT_SIZE + 1];
const auto fact_init = [] {
    Fact[0] = mint::raw(1);
    for(int i = 1; i <= FACT_SIZE; ++i) {
        Fact[i] = Fact[i-1] * i;
    }
    iFact[FACT_SIZE] = Fact[FACT_SIZE].inv();
    for(int i = FACT_SIZE; i; --i) {
        iFact[i-1] = iFact[i] * i;
    }
    return false;
}();

mint comb(int n, int k) {
    if (k == 0) return mint::raw(1);
    assert(n >= 0 && k >= 0);
    if (k > n) return mint::raw(0);
    return Fact[n] * iFact[n - k] * iFact[k];
}

mint icomb(int n, int k) {
    return iFact[n] * Fact[n - k] * Fact[k];
}

mint fact(int n) {return Fact[n];}
mint perm(int n, int k) {
    assert(0 <= n);
    return Fact[n] * iFact[n - k];
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  VI a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  constexpr int INF = 1001001001;
  deque<vector<mint>> q;
  int base = 0;
  rep(r, m) {
    int amn = INF, bmn = INF;
    for(int i = r; i < n; i += m) {
      chmin(amn, a[i]);
      chmin(bmn, b[i]);
    }
    int sz = amn + bmn + 1;
    vector<mint> f(sz, 1);
    for(int i = r; i < n; i += m) {
      int sm = a[i] + b[i];
      rep(j, sz) f[j] *= comb(sm, b[i] - bmn + j);
    }
    q.emplace_back(move(f));
    base += bmn;
  }
  while(q.size() >= 2) {
    auto f = move(q.front()); q.pop_front();
    auto g = move(q.front()); q.pop_front();
    q.emplace_back(convolution(f, g));
  }
  mint ans = q[0][base];
  cout << ans.val() << '\n';
}
0