AtCoder Grand Contest 005

Submission #1591313

Source codeソースコード

#include<iostream>
#include<cstdio>
#include<cstring>
namespace Math
{
	typedef long long ll;
	const int N=200010,M=525000,MOD=924844033;
	ll qpow(ll a,ll b){ll c=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)c=c*a%MOD;return c;}
	int dec[M];
	void getdec(int n){dec[0]=0;for(int i=1;i<n;i++)dec[i]=(dec[i>>1]>>1)+((i&1)?(n>>1):0);}
	void ntt(ll *y,int n,int rag)
	{
		for(int i=0;i<n;i++)
			if(dec[i]<i)std::swap(y[i],y[dec[i]]);
		for(int len=2;len<=n;len<<=1)
		{
			int h=len>>1;
			ll delta=qpow(5,(MOD-1)/len),x,*y0,*y1,ny0,ny1;

			if(rag<0)delta=qpow(delta,MOD-2);

			for(int p=0;p<n;p+=len)
			{
				y0=y+p,y1=y0+h,x=1;
				for(int i=0;i<h;i++,x=x*delta%MOD)
				{
					ny0=(y0[i]+x*y1[i])%MOD;
					ny1=(y0[i]-x*y1[i])%MOD;
					y0[i]=ny0;
					y1[i]=ny1;
				}
			}
		}
	}
	ll A[M],B[M];
	int m;
	void multi()
	{
		getdec(m);
		ntt(A,m,1),ntt(B,m,1);
		for(int i=0;i<m;i++)
			A[i]=A[i]*B[i]%MOD;
		ntt(A,m,-1);
		ll tmp=qpow(m,MOD-2);
		for(int i=0;i<m;i++)
			A[i]=(A[i]*tmp%MOD+MOD)%MOD;
	}

	ll fact[N],ifact[N];
	void calc(int *b,int *ans,int n)
	{
		for(m=1;m<=n+n;m<<=1);
		for(int i=fact[0]=1;i<=n;i++)fact[i]=fact[i-1]*i%MOD;
		ifact[n]=qpow(fact[n],MOD-2);
		for(int i=n;i;i--)ifact[i-1]=ifact[i]*i%MOD;

		for(int i=1;i<=n;i++)A[i]=b[i]*fact[i]%MOD;
		for(int i=0;i<=n;i++)B[i]=ifact[n-i];
		multi();

		for(int i=1;i<=n;i++)
			ans[i]=(A[n+i]*ifact[i]%MOD+MOD)%MOD;
	}
}
namespace O_O
{
	typedef long long ll;
	const int N=201000,M=N*2,MOD=924844033;
	int begin[N],next[M],to[M];
	int cnt[N],ans[N];
	int n,e;
	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	void initialize()
	{
		scanf("%d",&n);
		for(int i=1,u,v;i<n;i++)
			scanf("%d%d",&u,&v),add(u,v);
	}

	int dfs(int p=1,int h=0)
	{
		int sizp=1,x;
		for(int i=begin[p],q;i;i=next[i])
			if((q=to[i])!=h)
			{
				sizp+=(x=dfs(q,p));
				cnt[x]--;
				cnt[n-x]--;
			}
		return sizp;
	}
	void solve()
	{
		initialize();
		dfs();
		cnt[n]=n;
		Math::calc(cnt,ans,n);
		for(int i=1;i<=n;i++)
			printf("%d\n",ans[i]);
	}
}
int main()
{
	O_O::solve();
	return 0;
}

Submission

Task問題 F - Many Easy Problems
User nameユーザ名 Demerzel_IV
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1900
Source lengthソースコード長 2199 Byte
File nameファイル名
Exec time実行時間 176 ms
Memory usageメモリ使用量 29056 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘void O_O::initialize()’:
./Main.cpp:81:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:83:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v),add(u,v);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - example0,example1,example2
All 1900 / 1900 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
doublestar0 AC 168 ms 20224 KB
doublestar1 AC 168 ms 20224 KB
doublestar2 AC 168 ms 20224 KB
doublestar3 AC 168 ms 20224 KB
doublestar4 AC 168 ms 20224 KB
example0 AC 3 ms 12544 KB
example1 AC 3 ms 12544 KB
example2 AC 3 ms 12544 KB
line0 AC 176 ms 28928 KB
line1 AC 176 ms 28928 KB
line2 AC 176 ms 29056 KB
line3 AC 176 ms 28928 KB
line4 AC 176 ms 28928 KB
maxrand0 AC 175 ms 20480 KB
maxrand1 AC 175 ms 20480 KB
maxrand10 AC 176 ms 20480 KB
maxrand11 AC 176 ms 20480 KB
maxrand12 AC 176 ms 20480 KB
maxrand13 AC 175 ms 20480 KB
maxrand14 AC 176 ms 20480 KB
maxrand15 AC 176 ms 20480 KB
maxrand16 AC 175 ms 20480 KB
maxrand17 AC 175 ms 20480 KB
maxrand18 AC 176 ms 20480 KB
maxrand19 AC 175 ms 20480 KB
maxrand2 AC 176 ms 20480 KB
maxrand3 AC 176 ms 20480 KB
maxrand4 AC 175 ms 20480 KB
maxrand5 AC 176 ms 20480 KB
maxrand6 AC 176 ms 20480 KB
maxrand7 AC 175 ms 20480 KB
maxrand8 AC 175 ms 20480 KB
maxrand9 AC 176 ms 20480 KB
rand0 AC 5 ms 12544 KB
rand1 AC 3 ms 12544 KB
rand2 AC 5 ms 12544 KB
rand3 AC 5 ms 12544 KB
rand4 AC 4 ms 12544 KB
rand5 AC 5 ms 12544 KB
rand6 AC 4 ms 12544 KB
rand7 AC 5 ms 12544 KB
rand8 AC 4 ms 12544 KB
rand9 AC 4 ms 12544 KB
star0 AC 166 ms 20224 KB
star1 AC 166 ms 20224 KB
star2 AC 166 ms 20224 KB
star3 AC 166 ms 20224 KB
star4 AC 166 ms 20224 KB