結果

問題 No.1241 Eternal Tours
ユーザー 👑 kmjpkmjp
提出日時 2020-09-26 13:05:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,073 ms / 6,000 ms
コード長 2,180 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 207,328 KB
実行使用メモリ 44,156 KB
最終ジャッジ日時 2023-09-11 09:17:56
合計ジャッジ時間 19,097 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 308 ms
19,480 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 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 367 ms
12,108 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 93 ms
5,420 KB
testcase_17 AC 1,070 ms
44,080 KB
testcase_18 AC 825 ms
22,540 KB
testcase_19 AC 820 ms
20,208 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 16 ms
4,380 KB
testcase_22 AC 992 ms
31,676 KB
testcase_23 AC 23 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 387 ms
19,308 KB
testcase_29 AC 409 ms
19,416 KB
testcase_30 AC 527 ms
19,488 KB
testcase_31 AC 331 ms
11,312 KB
testcase_32 AC 1,073 ms
44,148 KB
testcase_33 AC 992 ms
21,968 KB
testcase_34 AC 687 ms
19,292 KB
testcase_35 AC 684 ms
19,476 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1,009 ms
21,868 KB
testcase_39 AC 927 ms
20,804 KB
testcase_40 AC 703 ms
19,296 KB
testcase_41 AC 924 ms
44,156 KB
testcase_42 AC 767 ms
20,912 KB
testcase_43 AC 541 ms
19,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X,Y,A,B,C,D;
ll T;
const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

template<class T> vector<T> fft(vector<T> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		T wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			T w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				T t1=v[j1],t2=(ll)w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=(ll)w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=(ll)v[i]*rv%mo;
	}
	return v;
}

void fft2d(vector<vector<ll>>& dp,bool rev=false) {
	int Y=dp.size();
	int X=dp[0].size();
	int y,x;
	FORR(d,dp) d=fft(d,rev);
	FOR(x,X) {
		vector<ll> V(Y);
		FOR(y,Y) V[y]=dp[y][x];
		V=fft(V,rev);
		FOR(y,Y) dp[y][x]=V[y];
	}
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>Y>>T>>A>>B>>C>>D;
	vector<vector<ll>> dp(1<<(X+1),vector<ll>(1<<(Y+1)));
	vector<vector<ll>> M(1<<(X+1),vector<ll>(1<<(Y+1)));
	
	dp[A][B]=dp[(1<<(X+1))-A][(1<<(Y+1))-B]=1;
	dp[A][(1<<(Y+1))-B]=dp[(1<<(X+1))-A][B]=mo-1;
	M[0][0]=M[0][1]=M[1][0]=M[(1<<(X+1))-1][0]=M[0][(1<<(Y+1))-1]=1;
	
	fft2d(dp);
	fft2d(M);
	FOR(x,dp.size()) FOR(y,dp[0].size()) {
		dp[x][y]=dp[x][y]*modpow(M[x][y],T)%mo;
	}
	
	fft2d(dp,1);
	cout<<dp[C][D]<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0