結果

問題 No.1772 Many DELETEQs
ユーザー 👑 hitonanodehitonanode
提出日時 2021-11-23 21:47:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,700 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 94,780 KB
実行使用メモリ 7,652 KB
最終ジャッジ日時 2023-09-08 02:18:26
合計ジャッジ時間 6,891 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 74 ms
4,380 KB
testcase_02 AC 143 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// TLE
#include <cassert>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;

#include <atcoder/modint>
using mint = atcoder::modint998244353;

template <typename modint> struct acl_fac {
    std::vector<modint> facs, facinvs;
    acl_fac(int N) {
        assert(-1 <= N and N < modint::mod());
        facs.resize(N + 1, 1);
        for (int i = 1; i <= N; i++) facs[i] = facs[i - 1] * i;
        facinvs.assign(N + 1, facs.back().inv());
        for (int i = N; i > 0; i--) facinvs[i - 1] = facinvs[i] * i;
    }
    modint ncr(int n, int r) const {
        if (n < 0 or r < 0 or n < r) return 0;
        return facs[n] * facinvs[r] * facinvs[n - r];
    }
    modint operator[](int i) const { return facs[i]; }
    modint finv(int i) const { return facinvs[i]; }
};
acl_fac<mint> fac(10000);

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int Q;
    cin >> Q;

    map<pair<int, int>, int> cache;
    while (Q--) {
        int X, Y;
        cin >> X >> Y;

        if (X > Y) swap(X, Y);

        if (cache.count(make_pair(X, Y))) {
            cout << cache[make_pair(X, Y)] << '\n';
            continue;
        }

        int K = Y - X;

        mint ret = 0;

        mint pow2 = 1;                         // 2^i
        for (int i = 0; i <= X; ++i) {         // i: (# of AA) + (# of BB)
            for (int j = 0; i + j <= X; ++j) { // j: (# of AB)
                int k = j + K;                 // k: (# of BA)
                ret += fac.ncr(i + j + k, i) * fac.ncr(j + k, j) * pow2;
            }
            pow2 *= 2;
        }

        cache[make_pair(X, Y)] = ret.val();
        cout << ret.val() << '\n';
    }
}
0