結果

問題 No.1241 Eternal Tours
ユーザー pes_magicpes_magic
提出日時 2020-09-26 18:59:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,302 ms / 6,000 ms
コード長 2,356 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 78,368 KB
実行使用メモリ 76,896 KB
最終ジャッジ日時 2023-09-12 00:20:44
合計ジャッジ時間 22,625 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 242 ms
36,100 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 272 ms
20,764 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 92 ms
7,748 KB
testcase_17 AC 2,302 ms
76,888 KB
testcase_18 AC 736 ms
40,848 KB
testcase_19 AC 741 ms
36,600 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 32 ms
4,468 KB
testcase_22 AC 1,333 ms
56,448 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 392 ms
36,124 KB
testcase_29 AC 388 ms
36,164 KB
testcase_30 AC 454 ms
36,136 KB
testcase_31 AC 262 ms
19,520 KB
testcase_32 AC 2,253 ms
76,896 KB
testcase_33 AC 955 ms
38,160 KB
testcase_34 AC 638 ms
36,184 KB
testcase_35 AC 631 ms
35,960 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1,214 ms
37,820 KB
testcase_39 AC 984 ms
37,052 KB
testcase_40 AC 792 ms
35,960 KB
testcase_41 AC 1,756 ms
76,840 KB
testcase_42 AC 676 ms
36,748 KB
testcase_43 AC 499 ms
36,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

long long modPow(long long a, long long p){
    if(p == 0) return 1;
    auto res = modPow(a, p/2);
    res = (res*res)%MOD;
    if(p%2) res = (res*a)%MOD;
    return res;
}

long long calcInv(long long a){
    return modPow(a, MOD-2);
}

void ntt(vector<long long>& v, int inv){
    const int n = v.size();
    auto w = modPow(3, (MOD-1)/n);
    if(inv == -1) w = calcInv(w);
    int rev = 0;
    for(int i=1;i<n-1;i++){
        for(int j=n/2;j>(rev^=j);j/=2);
        if(i < rev) swap(v[i], v[rev]);
    }
    for(int m=1;m<n;m*=2){
        auto cur = 1;
        auto rot = modPow(w, n/(2*m));
        for(int i=0;i<m;i++){
            for(int j=i;j<n;j+=2*m){
                auto p = v[j];
                auto q = v[j+m] * cur % MOD;
                v[j] = (p + q) % MOD;
                v[j+m] = (p + MOD - q) % MOD;
            }
            cur = (cur * rot) % MOD;
        }
    }
}

void ntt2d(vector<vector<long long>>& v, int inv){
    for(auto& t : v) ntt(t, inv);
    vector<long long> m(v.size());
    for(int i=0;i<v[0].size();i++){
        for(int j=0;j<v.size();j++) m[j] = v[j][i];
        ntt(m, inv);
        for(int j=0;j<v.size();j++) v[j][i] = m[j];
    }
}

vector<vector<long long>> mul(const vector<vector<long long>>& a, const vector<vector<long long>>& b){
    auto res = a;
    for(int i=0;i<a.size();i++){
        for(int j=0;j<a[i].size();j++) res[i][j] = a[i][j] * b[i][j] % MOD;
    }
    return res;
}

vector<vector<long long>> pow(const vector<vector<long long>>& a, long long p){
    if(p == 1) return a;
    auto r = pow(a, p/2);
    r = mul(r, r);
    if(p%2 == 1) r = mul(r, a);
    return r;
}

int main(){
    int X, Y;
    while(cin >> X >> Y){
        long long T; cin >> T;
        int a, b, c, d; cin >> a >> b >> c >> d;
        int N = 1 << (X+1);
        int M = 1 << (Y+1);
        vector<vector<long long>> f(N, vector<long long>(M, 0LL));
        f[0][0] = f[0][1] = f[1][0] = f[N-1][0] = f[0][M-1] = 1;
        vector<vector<long long>> g(N, vector<long long>(M, 0LL));
        g[a][b] = g[N-a][M-b] = 1;
        g[a][M-b] = g[N-a][b] = MOD - 1;
        ntt2d(f, 1);
        ntt2d(g, 1);
        auto res = mul(pow(f, T), g);
        ntt2d(res, -1);
        cout << res[c][d] * calcInv(N*M) % MOD << endl;
    }
}
0