結果

問題 No.1241 Eternal Tours
ユーザー chocoruskchocorusk
提出日時 2020-09-26 01:29:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 734 ms / 6,000 ms
コード長 3,032 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 135,792 KB
実行使用メモリ 83,000 KB
最終ジャッジ日時 2023-09-10 18:25:14
合計ジャッジ時間 12,699 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 199 ms
36,132 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 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,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 254 ms
20,872 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 64 ms
7,708 KB
testcase_17 AC 734 ms
83,000 KB
testcase_18 AC 557 ms
41,712 KB
testcase_19 AC 518 ms
36,640 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 12 ms
4,668 KB
testcase_22 AC 622 ms
59,268 KB
testcase_23 AC 17 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 320 ms
36,072 KB
testcase_29 AC 322 ms
36,084 KB
testcase_30 AC 372 ms
35,940 KB
testcase_31 AC 233 ms
19,364 KB
testcase_32 AC 731 ms
82,960 KB
testcase_33 AC 627 ms
37,852 KB
testcase_34 AC 476 ms
36,004 KB
testcase_35 AC 475 ms
36,020 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 658 ms
37,672 KB
testcase_39 AC 594 ms
37,788 KB
testcase_40 AC 503 ms
36,068 KB
testcase_41 AC 595 ms
82,972 KB
testcase_42 AC 429 ms
37,836 KB
testcase_43 AC 340 ms
35,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
const ll MOD=998244353;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
const ll r=3;
struct NTT{
	ll zeta[24];
	NTT(){
		zeta[23]=powmod(r, (MOD-1)>>23);
		for(int i=22; i>=0; i--) zeta[i]=zeta[i+1]*zeta[i+1]%MOD;
	}
	vector<ll> fft(vector<ll> a, int k, bool inverse=false){
		int n=a.size();
		vector<ll> tmp(n);
		for(int t=1; t<=k; t++){
			ll w=1, z=zeta[t];
			if(inverse) z=inv(z);
			for(int i=0; i<n; i++){
				int l=i&((1<<(k-t))-1), h=i&~((1<<(k-t))-1);
				tmp[i]=(a[((h<<1)|l)&(n-1)]+w*a[((h<<1)|l|(1<<(k-t)))&(n-1)])%MOD;
				if((i&((1<<(k-t))-1))==(1<<(k-t))-1) (w*=z)%=MOD;
			}
			swap(a, tmp);
		}
		if(inverse){
			ll invn=inv(n);
			for(int i=0; i<n; i++) (a[i]*=invn)%=MOD;
		}
		return a;
	}
	vector<ll> multiply(vector<ll> a, vector<ll> b){
		int n=a.size()+b.size()-1, k=0;
		while((1<<k)<n) k++;
		n=(1<<k);
		a.resize(n), b.resize(n);
		a=fft(a, k), b=fft(b, k);
		vector<ll> c(n);
		for(int i=0; i<n; i++) c[i]=a[i]*b[i]%MOD;
		c=fft(c, k, true);
		return c;
	}
};
NTT ntt;
vector<vector<ll>> fft_2d(vector<vector<ll>> v, int n, int m, bool inverse=false){
    vector<vector<ll>> fv(1<<n);
    for(int i=0; i<(1<<n); i++) fv[i]=ntt.fft(v[i], m, inverse);
    for(int j=0; j<(1<<m); j++){
        vector<ll> vh(1<<n);
        for(int i=0; i<(1<<n); i++) vh[i]=fv[i][j];
        vh=ntt.fft(vh, n, inverse);
        for(int i=0; i<(1<<n); i++) fv[i][j]=vh[i];
    }
    return fv;
}
int main()
{
    int x, y;
    ll t;
    int a, b, c, d;
    cin>>x>>y>>t>>a>>b>>c>>d;
    vector<vector<ll>> v(1<<(x+1), vector<ll>(1<<(y+1)));
    v[0][0]=v[1][0]=v[0][1]=v[(1<<(x+1))-1][0]=v[0][(1<<(y+1))-1]=1;
    //v[a][b]=1, v[(1<<(x+1))-a][b]=MOD-1, v[a][(1<<(y+1))-b]=MOD-1, v[(1<<(x+1))-a][(1<<(y+1))-b]=1;
    auto fv=fft_2d(v, x+1, y+1);
    for(int i=0; i<(1<<(x+1)); i++){
        for(int j=0; j<(1<<(y+1)); j++){
            fv[i][j]=powmod(fv[i][j], t);
        }
    }
    auto vp=fft_2d(fv, x+1, y+1, true);
    int a1[4]={a, (1<<(x+1))-a, (1<<(x+1))-a, a};
    int b1[4]={b, (1<<(y+1))-b, b, (1<<(y+1))-b};
    int maskx=(1<<(x+1))-1, masky=(1<<(y+1))-1;
    ll ans=0;
    for(int i=0; i<4; i++){
        ll z=vp[(c-a1[i]+(1<<(x+1)))&maskx][(d-b1[i]+(1<<(y+1)))&masky];
        if(i<2) ans+=z;
        else ans+=MOD-z;
    }
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}
0