提出 #25305769


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
	int s=1,a=0;
	char c=getchar();
	while(!isdigit(c)) {
		if(c=='-') s=-s;
		c=getchar();
	}
	while(isdigit(c)) {
		a=a*10+c-'0';
		c=getchar();
	}
	return s*a;
}
const int N=6e5+8,Mod=924844033,G=5,IG=554906420;
int re[N],f[N],g[N],jc[N],jcinv[N],n;
int ksm(int a,int b) {
	int c=1;
	while(b) {
		if(b&1) c*=a,c%=Mod;
		a*=a,a%=Mod;
		b>>=1;
	}
	return c;
}
void init() {
	jc[0]=1;
	for(int i=1; i<=n; i++) jc[i]=jc[i-1]*i%Mod;
	jcinv[n]=ksm(jc[n],Mod-2);
	for(int i=n; i>=1; i--) jcinv[i-1]=jcinv[i]*i%Mod;
}
void ntt(int *arr,int len,int op) {
	for(int i=0; i<len; i++) {
		if(i<re[i]) swap(arr[i],arr[re[i]]);
	}
	for(int i=2; i<=len; i<<=1) {
		int wn=ksm(op==1?G:IG,(Mod-1)/i);
		for(int j=0; j<len; j+=i) {
			int wk=1;
			for(int k=j; k<j+(i>>1); k++,wk=wk*wn%Mod) {
				int xx=arr[k],yy=arr[k+(i>>1)]*wk%Mod;
				arr[k]=(xx+yy)%Mod;
				arr[k+(i>>1)]=(xx-yy+Mod)%Mod;
			}
		}
	}
}
int C(int a,int b) {
	return jc[a]*jcinv[b]%Mod*jcinv[a-b]%Mod;
}
int siz[N],cnt[N];
vector <int> T[N];
void dfs(int u,int fa) {
	siz[u]=1;
	for(auto v:T[u]) {
		if(v==fa) continue;
		dfs(v,u);
		siz[u]+=siz[v];
		cnt[siz[v]]++;
	}
	cnt[n-siz[u]]++;
}
int ans[N];
signed main() {
	n=read();
	for(int i=1; i<n; i++) {
		int a=read(),b=read();
		T[a].push_back(b);
		T[b].push_back(a);
	}
	dfs(1,0);
	init();
	for(int i=1; i<=n; i++) {
		f[n-i]=cnt[i]*jc[i]%Mod;
		g[i]=jcinv[i];
	}
	g[0]=1;
	int len=1,tim=0;
	while(len<=(n<<1)) len<<=1,tim++;
	int invlen=ksm(len,Mod-2);
	for(int i=0; i<len; i++) re[i]=(re[i>>1]>>1)|((i&1)<<(tim-1));
	ntt(f,len,1),ntt(g,len,1);
	for(int i=0; i<len; i++) f[i]=f[i]*g[i]%Mod;
	ntt(f,len,-1);
	for(int i=0; i<len; i++) f[i]=f[i]*invlen%Mod;
//	reverse(f,f+n+1);
	for(int i=1; i<=n; i++) {
		ans[i]=(C(n,i)*n%Mod-jcinv[i]*f[n-i]%Mod+Mod)%Mod;
	}
	for(int i=1; i<=n; i++) printf("%lld\n",ans[i]);
	return 0;
}

提出情報

提出日時
問題 F - Many Easy Problems
ユーザ rpdg
言語 C++ (GCC 9.2.1)
得点 1900
コード長 2009 Byte
結果 AC
実行時間 201 ms
メモリ 57832 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 1900 / 1900
結果
AC × 3
AC × 48
セット名 テストケース
Sample example0, example1, example2
All doublestar0, doublestar1, doublestar2, doublestar3, doublestar4, example0, example1, example2, line0, line1, line2, line3, line4, maxrand0, maxrand1, maxrand10, maxrand11, maxrand12, maxrand13, maxrand14, maxrand15, maxrand16, maxrand17, maxrand18, maxrand19, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, star0, star1, star2, star3, star4
ケース名 結果 実行時間 メモリ
doublestar0 AC 165 ms 42840 KiB
doublestar1 AC 163 ms 42812 KiB
doublestar2 AC 162 ms 42660 KiB
doublestar3 AC 161 ms 42824 KiB
doublestar4 AC 162 ms 42760 KiB
example0 AC 19 ms 17720 KiB
example1 AC 17 ms 17612 KiB
example2 AC 16 ms 17672 KiB
line0 AC 182 ms 57616 KiB
line1 AC 177 ms 57648 KiB
line2 AC 181 ms 57832 KiB
line3 AC 177 ms 57772 KiB
line4 AC 177 ms 57680 KiB
maxrand0 AC 197 ms 44032 KiB
maxrand1 AC 190 ms 44140 KiB
maxrand10 AC 192 ms 43944 KiB
maxrand11 AC 190 ms 43808 KiB
maxrand12 AC 194 ms 44016 KiB
maxrand13 AC 193 ms 44068 KiB
maxrand14 AC 193 ms 44032 KiB
maxrand15 AC 195 ms 44020 KiB
maxrand16 AC 196 ms 44008 KiB
maxrand17 AC 193 ms 43948 KiB
maxrand18 AC 193 ms 43832 KiB
maxrand19 AC 194 ms 43984 KiB
maxrand2 AC 192 ms 43964 KiB
maxrand3 AC 188 ms 43900 KiB
maxrand4 AC 197 ms 44044 KiB
maxrand5 AC 194 ms 43920 KiB
maxrand6 AC 190 ms 43948 KiB
maxrand7 AC 186 ms 44168 KiB
maxrand8 AC 193 ms 43968 KiB
maxrand9 AC 201 ms 43920 KiB
rand0 AC 20 ms 18072 KiB
rand1 AC 16 ms 17696 KiB
rand2 AC 19 ms 18004 KiB
rand3 AC 18 ms 18132 KiB
rand4 AC 15 ms 17864 KiB
rand5 AC 23 ms 18144 KiB
rand6 AC 17 ms 18032 KiB
rand7 AC 20 ms 18112 KiB
rand8 AC 15 ms 17848 KiB
rand9 AC 16 ms 17848 KiB
star0 AC 158 ms 43520 KiB
star1 AC 156 ms 43600 KiB
star2 AC 157 ms 43484 KiB
star3 AC 158 ms 43468 KiB
star4 AC 158 ms 43540 KiB