結果

問題 No.1772 Many DELETEQs
ユーザー 👑 hitonanodehitonanode
提出日時 2021-11-23 20:00:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 3,500 ms
コード長 1,188 bytes
コンパイル時間 6,087 ms
コンパイル使用メモリ 217,376 KB
実行使用メモリ 66,456 KB
最終ジャッジ日時 2023-09-08 01:14:38
合計ジャッジ時間 9,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
66,264 KB
testcase_01 AC 131 ms
66,236 KB
testcase_02 AC 130 ms
66,440 KB
testcase_03 AC 212 ms
66,208 KB
testcase_04 AC 208 ms
66,220 KB
testcase_05 AC 212 ms
66,200 KB
testcase_06 AC 179 ms
66,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include <iostream>
#include <vector>
#include <atcoder/modint>
using namespace std;

constexpr int D = 4000;

int main(int argc, char *argv[]) {
    registerValidation(argc, argv);

    vector dp(D + 1, vector<atcoder::modint998244353>(D + 1)); // dp[x][y]: 最少で AB x 個 BA y 個で作れる列の個数
    dp[0][0] = 1;

    for (int i = 0; i < int(dp.size()); ++i) {
        for (int j = 0; j < int(dp[i].size()); ++j) {
            // AA 始まり / BB 始まり
            if (i and j) dp[i][j] += dp[i - 1][j - 1] * 2;

            // AB 始まり
            if (i) dp[i][j] += dp[i - 1][j];

            // BA 始まり
            if (j) dp[i][j] += dp[i][j - 1];
        }
    }

    for (int i = 1; i < int(dp.size()); ++i) {
        for (int j = 1; j < int(dp[i].size()); ++j) dp[i][j] += dp[i - 1][j - 1];
    }

    int Q = inf.readInt(1, 200000);
    inf.readEoln();
    
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    while (Q--) {
        int x = inf.readInt(1, 4000);
        inf.readSpace();
        int y = inf.readInt(1, 4000);
        inf.readEoln();
        cout << dp.at(x).at(y).val() << '\n';
    }
    inf.readEof();
}
0