結果

問題 No.1241 Eternal Tours
ユーザー 👑 hitonanodehitonanode
提出日時 2021-02-21 00:34:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 435 ms / 6,000 ms
コード長 1,860 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 116,840 KB
実行使用メモリ 33,212 KB
最終ジャッジ日時 2023-10-19 03:13:02
合計ジャッジ時間 10,558 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 111 ms
11,576 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 198 ms
8,144 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 50 ms
5,100 KB
testcase_17 AC 431 ms
33,212 KB
testcase_18 AC 418 ms
14,292 KB
testcase_19 AC 374 ms
11,912 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 404 ms
22,328 KB
testcase_23 AC 14 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 229 ms
11,576 KB
testcase_29 AC 230 ms
11,576 KB
testcase_30 AC 283 ms
11,576 KB
testcase_31 AC 188 ms
7,616 KB
testcase_32 AC 435 ms
33,212 KB
testcase_33 AC 395 ms
12,652 KB
testcase_34 AC 384 ms
11,576 KB
testcase_35 AC 383 ms
11,576 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 412 ms
12,652 KB
testcase_39 AC 405 ms
12,140 KB
testcase_40 AC 406 ms
11,576 KB
testcase_41 AC 296 ms
33,212 KB
testcase_42 AC 247 ms
12,140 KB
testcase_43 AC 245 ms
11,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <atcoder/convolution>
#include <iostream>
using namespace std;
using mint = atcoder::modint998244353;

template <typename MODINT>
void ntt2d(std::vector<std::vector<MODINT>> &mat)
{
    for (auto &vec : mat) atcoder::internal::butterfly(vec);
    int h = mat.size(), w = mat[0].size();
    for (int j = 0; j < w; j++)
    {
        std::vector<MODINT> v(h);
        for (int i = 0; i < h; i++) v[i] = mat[i][j];
        atcoder::internal::butterfly(v);
        for (int i = 0; i < h; i++) mat[i][j] = v[i];
    }
}
template <typename MODINT>
void ntt2dinv(std::vector<std::vector<MODINT>> &mat)
{
    int h = mat.size(), w = mat[0].size();
    for (int j = 0; j < w; j++)
    {
        std::vector<MODINT> v(h);
        for (int i = 0; i < h; i++) v[i] = mat[i][j];
        atcoder::internal::butterfly_inv(v);
        for (int i = 0; i < h; i++) mat[i][j] = v[i];
    }
    for (auto &vec : mat) atcoder::internal::butterfly_inv(vec);
    MODINT ninv = MODINT(h * w).inv();
    for (auto &vec : mat)
    {
        for (auto &x : vec)
        {
            x *= ninv;
        }
    }
}

int main()
{
    int X, Y;
    long long T;
    int a, b, c, d;
    cin >> X >> Y >> T >> a >> b >> c >> d;

    vector dp(1 << (X + 1), vector<mint>(1 << (Y + 1)));
    dp[a][b] = 1;
    dp[(1 << (X + 1)) - a][(1 << (Y + 1)) - b] = 1;
    dp[(1 << (X + 1)) - a][b] = -1;
    dp[a][(1 << (Y + 1)) - b] = -1;

    vector trans(1 << (X + 1), vector<mint>(1 << (Y + 1)));
    trans[0][0] = trans[0][1] = trans[0][(1 << (Y + 1)) - 1] = trans[1][0] = trans[(1 << (X + 1)) - 1][0] = 1;

    ntt2d(dp);
    ntt2d(trans);
    for (size_t i = 0; i < dp.size(); i++)
    {
        for (size_t j = 0; j < dp[i].size(); j++)
        {
            dp[i][j] *= trans[i][j].pow(T);
        }
    }
    ntt2dinv(dp);
    cout << dp[c][d].val() << '\n';
}
0