結果

問題 No.2810 Have Another Go (Hard)
ユーザー 👑 kmjpkmjp
提出日時 2024-07-14 23:50:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,277 ms / 3,000 ms
コード長 2,588 bytes
コンパイル時間 3,489 ms
コンパイル使用メモリ 212,532 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-07-14 23:50:59
合計ジャッジ時間 48,709 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1,199 ms
8,064 KB
testcase_02 AC 1,271 ms
8,064 KB
testcase_03 AC 1,277 ms
8,064 KB
testcase_04 AC 1,230 ms
8,064 KB
testcase_05 AC 1,203 ms
8,192 KB
testcase_06 AC 1,218 ms
8,064 KB
testcase_07 AC 1,216 ms
8,064 KB
testcase_08 AC 1,205 ms
8,064 KB
testcase_09 AC 1,193 ms
8,064 KB
testcase_10 AC 1,161 ms
8,192 KB
testcase_11 AC 7 ms
6,940 KB
testcase_12 AC 8 ms
6,944 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 9 ms
6,944 KB
testcase_15 AC 7 ms
6,944 KB
testcase_16 AC 274 ms
6,944 KB
testcase_17 AC 1,029 ms
7,552 KB
testcase_18 AC 623 ms
6,944 KB
testcase_19 AC 989 ms
7,296 KB
testcase_20 AC 150 ms
6,940 KB
testcase_21 AC 341 ms
6,944 KB
testcase_22 AC 622 ms
6,944 KB
testcase_23 AC 445 ms
6,940 KB
testcase_24 AC 745 ms
6,944 KB
testcase_25 AC 1,109 ms
7,936 KB
testcase_26 AC 1,144 ms
8,064 KB
testcase_27 AC 1,174 ms
8,192 KB
testcase_28 AC 1,196 ms
8,192 KB
testcase_29 AC 1,202 ms
8,064 KB
testcase_30 AC 1,191 ms
8,064 KB
testcase_31 AC 1,224 ms
8,192 KB
testcase_32 AC 1,215 ms
8,064 KB
testcase_33 AC 1,193 ms
8,064 KB
testcase_34 AC 1,203 ms
8,192 KB
testcase_35 AC 1,199 ms
8,192 KB
testcase_36 AC 1,190 ms
8,064 KB
testcase_37 AC 1,195 ms
8,064 KB
testcase_38 AC 1,197 ms
8,064 KB
testcase_39 AC 1,195 ms
8,192 KB
testcase_40 AC 1,219 ms
8,192 KB
testcase_41 AC 1,219 ms
8,064 KB
testcase_42 AC 1,184 ms
8,064 KB
testcase_43 AC 1,192 ms
8,064 KB
testcase_44 AC 1,190 ms
8,192 KB
testcase_45 AC 1,201 ms
8,192 KB
testcase_46 AC 3 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 6 ms
6,940 KB
testcase_52 AC 4 ms
6,944 KB
testcase_53 AC 7 ms
6,940 KB
testcase_54 AC 8 ms
6,944 KB
testcase_55 AC 4 ms
6,940 KB
testcase_56 AC 7 ms
6,940 KB
testcase_57 AC 6 ms
6,944 KB
testcase_58 AC 5 ms
6,940 KB
testcase_59 AC 10 ms
6,940 KB
testcase_60 AC 6 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#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 ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll N,M,K;
const ll mo=998244353;

const int MAT=6;
struct Mat { ll v[MAT][MAT]; Mat(){ZERO(v);};};

Mat mulmat(Mat& a,Mat& b,int n=MAT) {
	ll mo2=4*mo*mo;
	int x,y,z; Mat r;
	FOR(x,n) FOR(y,n) r.v[x][y]=0;
	FOR(x,n) FOR(z,n) FOR(y,n) {
		r.v[x][y] += a.v[x][z]*b.v[z][y];
		if(r.v[x][y]>mo2) r.v[x][y] -= mo2;
	}
	FOR(x,n) FOR(y,n) r.v[x][y]%=mo;
	return r;
}

Mat powmat(ll p,Mat a,int n=MAT) {
	int i,x,y; Mat r;
	FOR(x,n) FOR(y,n) r.v[x][y]=0;
	FOR(i,n) r.v[i][i]=1;
	while(p) {
		if(p%2) r=mulmat(r,a,n);
		a=mulmat(a,a,n);
		p>>=1;
	}
	return r;
}

map<ll,ll> memo;
Mat A,B;
ll pat(ll v) {
	if(v<0) return 0;
	if(memo.count(v)) return memo[v];
	auto B=powmat(v,A);
	return memo[v]=B.v[0][0];
}



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	A.v[0][0]=A.v[0][1]=A.v[0][2]=A.v[0][3]=A.v[0][4]=A.v[0][5]=1;
	A.v[1][0]=A.v[2][1]=A.v[3][2]=A.v[4][3]=A.v[5][4]=1;
	
	
	cin>>N>>M>>K;
	
	//合計を求める
	ll sum=0;
	FOR(i,6) {
		ll p=pat(1LL*N*M-6+i);
		for(k=1;k<=6;k++) if(1LL*N*M-6+i+k>=1LL*N*M) sum+=p;
	}
	sum%=mo;
	

	FOR(i,5) {
		// 1周の手前jマス
		FOR(j,5) {
			ll a=pat(N-5+j-(i+1));
			for(k=1;k<=6;k++) if(N-5+j+k>N) {
				(B.v[(N-5+j+k)-(N+1)][i]+=a)%=mo;
			}
		}
	}
	
	B=powmat(M-1,B,5);
	while(K--) {
		cin>>k;
		
		ll p[6]={};
		FOR(j,5) {
			ll a=pat(k-5+j);
			//cout<<k-5+j<<" "<<a<<endl;
			for(i=1;i<=6;i++) if(k-5+j+i>k) (p[(k-5+j+i)-(k+1)]+=a)%=mo;
		}
		//FOR(j,5) cout<<"#"<<j<<" "<<p[j]<<endl;
		ll q[5]={};
		FOR(x,5) FOR(y,5) (q[y]+=p[x]*B.v[y][x])%=mo;
		//FOR(j,5) cout<<"##"<<j<<" "<<q[j]<<endl;
		ZERO(p);
		ll ret=0;
		
		FOR(x,5) {
			if(k+1+x>=N) {
				ret+=q[x];
			}
			else {
				FOR(y,6) (p[y]+=q[x]*pat((N-6+y)-(k+1+x)))%=mo;
			}
		}
		FOR(y,6) for(x=1;x<=6;x++) if(y+x>=6) ret+=p[y];
		cout<<(sum-ret%mo+mo)%mo<<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