結果

問題 No.1241 Eternal Tours
ユーザー carrot46carrot46
提出日時 2020-09-28 23:13:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 699 ms / 6,000 ms
コード長 5,569 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 178,508 KB
実行使用メモリ 47,272 KB
最終ジャッジ日時 2023-09-15 16:02:15
合計ジャッジ時間 12,396 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 170 ms
20,012 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 241 ms
12,228 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 56 ms
5,844 KB
testcase_17 AC 699 ms
47,272 KB
testcase_18 AC 529 ms
22,872 KB
testcase_19 AC 466 ms
20,788 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 606 ms
33,296 KB
testcase_23 AC 15 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 286 ms
19,868 KB
testcase_29 AC 287 ms
19,816 KB
testcase_30 AC 337 ms
19,820 KB
testcase_31 AC 214 ms
11,572 KB
testcase_32 AC 690 ms
47,260 KB
testcase_33 AC 588 ms
24,644 KB
testcase_34 AC 435 ms
20,092 KB
testcase_35 AC 434 ms
19,812 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 601 ms
24,664 KB
testcase_39 AC 525 ms
22,092 KB
testcase_40 AC 455 ms
19,860 KB
testcase_41 AC 543 ms
47,156 KB
testcase_42 AC 368 ms
22,260 KB
testcase_43 AC 301 ms
19,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr modint set_raw(ll _x){
        //_x in [0, mod)
        x = _x;
        return *this;
    }
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        if(x == 2) return (mod + 1) >> 1;
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod1 998244353
using mint = modint<mod1>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

class NTT{
    const int root;

    void make_root_pow(int n, vm &root_pow){
        root_pow.resize(n + 1);
        mint new_root = mint(root).pow((mod1 - 1) / n);
        root_pow[0].x = 1;
        rep(i,n){
            root_pow[i + 1] = root_pow[i] * new_root;
        }
    }
    static void make_bit_reverse(int n, vector<int> &v){
        v.resize(n);
        iota(ALL(v), 0);
        for(int i = 1; (1<<i) <= n; ++i){
            int l = 1<<(i - 1), r = 1<<i;
            int plus = n >> i;
            for(int j = l; j < r; ++j){
                int temp = v[j - l] + plus;
                if(j < temp) swap(v[j], v[temp]);
            }
        }
    }
    static void dft(int n, vm &f, bool inv, vm &root_pow, vector<int> &id){
        vm g(n);
        rep(i,n) g[i] = f[id[i]];
        swap(f, g);
        for(int l = n / 2, len = 1; l >= 1; l /= 2, len *= 2){
            for(int i = 0; i < n; i += len * 2){
                rep(j, len){
                    mint z_f = (inv ? root_pow[n - l * j] : root_pow[l * j]) * f[i + len + j];
                    g[i + j] = f[i + j] + z_f;
                    g[i + len + j] = f[i + j] - z_f;
                }
            }
            swap(f, g);
        }
        if(inv) {
            mint n_inv = mint(n).inv();
            rep(i, n) f[i] *= n_inv;
        }
    }
public:
    NTT(int _x = 3) : root(_x){}
    void dft_2D(int n, int m, vector<vm> &a, bool inv){
        //簡単に、書き換える形で
        //aがn×mサイズであることや、n,mが2冪であることは仮定
        vm root_pow;
        vector<int> id;
        make_root_pow(m, root_pow);
        make_bit_reverse(m, id);
        rep(i, n){
            dft(m, a[i], inv, root_pow, id);
        }
        make_root_pow(n, root_pow);
        make_bit_reverse(n, id);
        rep(j, m){
            vm temp(n);
            rep(i, n) temp[i] = a[i][j];
            dft(n, temp, inv, root_pow, id);
            rep(i, n) a[i][j] = temp[i];
        }
    }
    vm convolution(vm &a, vm &b, int size_a = INT_MAX, int size_b = INT_MAX){
        if(size_a > (int)a.size()) size_a = (int)a.size();
        if(size_b > (int)b.size()) size_b = (int)b.size();
        int sz = size_a + size_b - 1, n = 1;
        while(sz > n) n *= 2;
        vm g(n), h(n), root_pow, gh(n);
        vector<int> id;
        copy(a.begin(), a.begin() + size_a, g.begin());
        copy(b.begin(), b.begin() + size_b, h.begin());
        make_root_pow(n, root_pow);
        make_bit_reverse(n, id);
        dft(n, g, false, root_pow, id);
        dft(n, h, false, root_pow, id);
        rep(i, n) gh[i] = g[i] * h[i];
        dft(n, gh, true, root_pow, id);
        gh.resize(sz);
        return gh;
    }
};

vector<vm> dp, f;
int X, Y, a, b, c, d, n, m;
ll T;

int main() {
    cin>>X>>Y>>T>>a>>b>>c>>d;
    n = 1<<(X + 1);
    m = 1<<(Y + 1);
    dp.resize(n);
    f.resize(n);
    rep(i, n){
        dp[i].resize(m);
        f[i].resize(m);
    }
    dp[a][b] = dp[n - a][m - b] = 1;
    dp[a][m - b] = dp[n - a][b] = - 1;
    f[0][0] = f[0][1] = f[1][0] = f[n - 1][0] = f[0][m - 1] = 1;
    NTT ntt;
    ntt.dft_2D(n, m, dp, false);
    ntt.dft_2D(n, m, f, false);
    rep(i, n) rep(j, m) dp[i][j] *= f[i][j].pow(T);
    ntt.dft_2D(n, m, dp, true);
    cout<<dp[c][d]<<endl;
}
0