結果

問題 No.1387 Mitarushi's Remodeling
ユーザー 👑 kmjpkmjp
提出日時 2021-02-11 11:40:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 848 ms / 2,000 ms
コード長 2,793 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 207,436 KB
実行使用メモリ 83,812 KB
最終ジャッジ日時 2023-09-25 00:39:13
合計ジャッジ時間 62,274 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 353 ms
81,528 KB
testcase_01 AC 385 ms
81,468 KB
testcase_02 AC 383 ms
81,532 KB
testcase_03 AC 341 ms
81,576 KB
testcase_04 AC 342 ms
81,472 KB
testcase_05 AC 339 ms
81,588 KB
testcase_06 AC 329 ms
81,504 KB
testcase_07 AC 328 ms
81,584 KB
testcase_08 AC 612 ms
81,520 KB
testcase_09 AC 631 ms
81,676 KB
testcase_10 AC 617 ms
81,656 KB
testcase_11 AC 619 ms
81,668 KB
testcase_12 AC 621 ms
81,668 KB
testcase_13 AC 637 ms
81,496 KB
testcase_14 AC 811 ms
83,568 KB
testcase_15 AC 824 ms
83,492 KB
testcase_16 AC 809 ms
83,616 KB
testcase_17 AC 804 ms
83,608 KB
testcase_18 AC 814 ms
83,608 KB
testcase_19 AC 819 ms
83,628 KB
testcase_20 AC 804 ms
83,812 KB
testcase_21 AC 808 ms
83,452 KB
testcase_22 AC 810 ms
83,616 KB
testcase_23 AC 816 ms
83,552 KB
testcase_24 AC 818 ms
83,508 KB
testcase_25 AC 825 ms
83,724 KB
testcase_26 AC 819 ms
83,444 KB
testcase_27 AC 815 ms
83,616 KB
testcase_28 AC 812 ms
83,508 KB
testcase_29 AC 806 ms
83,452 KB
testcase_30 AC 811 ms
83,612 KB
testcase_31 AC 815 ms
83,616 KB
testcase_32 AC 804 ms
83,624 KB
testcase_33 AC 812 ms
83,484 KB
testcase_34 AC 807 ms
83,536 KB
testcase_35 AC 810 ms
83,628 KB
testcase_36 AC 811 ms
83,452 KB
testcase_37 AC 823 ms
83,624 KB
testcase_38 AC 832 ms
83,620 KB
testcase_39 AC 803 ms
83,608 KB
testcase_40 AC 805 ms
83,568 KB
testcase_41 AC 813 ms
83,620 KB
testcase_42 AC 823 ms
83,568 KB
testcase_43 AC 820 ms
83,480 KB
testcase_44 AC 832 ms
83,488 KB
testcase_45 AC 825 ms
83,616 KB
testcase_46 AC 815 ms
83,728 KB
testcase_47 AC 821 ms
83,484 KB
testcase_48 AC 830 ms
83,492 KB
testcase_49 AC 818 ms
83,448 KB
testcase_50 AC 818 ms
83,504 KB
testcase_51 AC 815 ms
83,500 KB
testcase_52 AC 815 ms
83,468 KB
testcase_53 AC 820 ms
83,624 KB
testcase_54 AC 822 ms
83,620 KB
testcase_55 AC 817 ms
83,504 KB
testcase_56 AC 821 ms
83,612 KB
testcase_57 AC 826 ms
83,624 KB
testcase_58 AC 824 ms
83,620 KB
testcase_59 AC 829 ms
83,488 KB
testcase_60 AC 815 ms
83,536 KB
testcase_61 AC 848 ms
83,456 KB
testcase_62 AC 822 ms
83,492 KB
testcase_63 AC 834 ms
83,484 KB
testcase_64 AC 827 ms
83,556 KB
testcase_65 AC 833 ms
83,616 KB
testcase_66 AC 829 ms
83,620 KB
testcase_67 AC 829 ms
83,624 KB
testcase_68 AC 631 ms
83,736 KB
testcase_69 AC 651 ms
83,480 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;}
//-------------------------------------------------------

int N,K;
ll A[505050];
const ll mo=998244353;

const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1],factrs[NUM_+1];

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;
}


template<class T> vector<T> MultPoly(vector<T> P,vector<T> Q,bool resize=false) {
	if(resize) {
		int maxind=0,pi=0,qi=0,i;
		int s=2;
		FOR(i,P.size()) if(norm(P[i])) pi=i;
		FOR(i,Q.size()) if(norm(Q[i])) qi=i;
		maxind=pi+qi+1;
		while(s*2<maxind) s*=2;
		P.resize(s*2);Q.resize(s*2);
	}
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=(ll)P[i]*Q[i]%mo;
	return fft(P,true);
}


ll Psum(int N,int K) {
	const int NUM_=1400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1],factrs[NUM_+1];
	if(fact[0]==0) {
		inv[1]=fact[0]=factr[0]=factrs[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo, factrs[i]=(factrs[i-1]+factr[i])%mo;
	}
	K=min(N,K);
	return fact[N]*(mo+factrs[N-1]-(N>K?factrs[N-K-1]:0))%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	vector<ll> B(1<<20),C(1<<20);
	ll Z=modpow(4);
	FOR(i,N) {
		cin>>A[i];
		B[i]=A[i]+1;
		C[N-1-i]=A[i]+1;
		Z=Z*A[i]%mo;
	}

	
	auto D=MultPoly(B,C);
	
	ll ret=0;
	for(int l=1;l<=N-1;l++) {
		ll P=D[N-1-l]*(Psum(N-1,K)+mo-Psum(N-1-l,K))%mo;
		(ret+=P*Z)%=mo;
	}
	cout<<ret<<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