結果

問題 No.1771 A DELETEQ
コンテスト
ユーザー hitonanode
提出日時 2021-11-23 12:00:53
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 140 ms / 3,500 ms
コード長 1,096 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 998 ms
コンパイル使用メモリ 93,420 KB
実行使用メモリ 66,048 KB
最終ジャッジ日時 2026-06-24 10:02:05
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 RE * 2 MLE * 2 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <atcoder/modint>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template <int md> std::istream &operator>>(std::istream &is, atcoder::static_modint<md> &x) {
    long long t;
    return is >> t, x = t, is;
}
template <int md> std::ostream &operator<<(std::ostream &os, const atcoder::static_modint<md> &x) { return os << x.val(); }

using mint = atcoder::modint998244353;

int main() {
    int X, Y;
    cin >> X >> Y;

    vector dp(X + 1, vector<mint>(Y + 1)); // dp[x][y]: 最小で AB x 個 BA y 個で作れる列の個数
    dp[0][0] = 1;

    mint ret = 0;

    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];

            if (j - i == Y - X) ret += dp[i][j];
        }
    }
    cout << ret.val() << '\n';
}
0