Submission #907061
Source Code Expand
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 924844033;
const int R_R = 5000;
const int SIZE = 1e6+10;
inline int pow(long long n,int k,int m){
unsigned i;
int a;
for(a=i=1;i<=k;i*=2,n=(n*n)%m)
if(k&i)a=(a*n)%m;
return a;
}
inline int rev(int n,int k){
int i=0;
while(k--)(i<<=1)+=n&1,n/=2;
return i;
}
const long long p=MOD,r=10;
void ntt(bool f,int& n,int s[]){
int i,j,k;
long long x,w;
for(j=1,k=0;j<n ;j<<=1,k++);
for(;n<j;n++)s[n]=0;
for(i=0;i<n;i++)
if(i<rev(i,k))
swap(s[i],s[rev(i,k)]);
for(i=2;i<=n;i*=2){
w=pow(pow(r,(p-1)/n,p),f?p-1-n/i:n/i,p);
for(j=0;j<n;j+=i)
for(k=0,x=1;k<i/2;k++){
int &a=s[j+k],&b=s[j+k+i/2];
b=(b*x)%p;
a=(a*1ll+b)%p;
b=(a+p+p-b-b)%p;
x=x*w%p;
}
}
x=pow(n,p-2,p);
if(f)for(j=0;j<n;j++)
s[j]=(s[j]*x)%p;
}
void mul(int n,int a[],int b[]){
for(int i=0;i<n;i++)
a[i]=(1ll*a[i]*b[i])%p;
}
LL fac[SIZE],inv[SIZE];
LL mypow(LL x,LL y){
LL res=1;
while(y){
if(y&1)res=res*x%MOD;
y>>=1;
x=x*x%MOD;
}
return res;
}
LL C(int x,int y){
if(y<0||y>x)return 0;
return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
void build(){
assert(MOD>=SIZE);
fac[0]=1;
REPP(i,1,SIZE)fac[i]=fac[i-1]*i%MOD;
inv[SIZE-1]=mypow(fac[SIZE-1],MOD-2);
for(int i=SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%MOD;
}
int s[1000000],t[1000000];
int num[SIZE],N;
VI e[SIZE];
bool u[SIZE];
int cnt[SIZE];
void dfs(int x){
u[x]=1;
num[x]=1;
REP(i,SZ(e[x])){
int y=e[x][i];
if(u[y])continue;
dfs(y);
num[x]+=num[y];
cnt[num[y]]++;
}
cnt[N-num[x]]++;
}
int an[SIZE];
void ADD(int &x,LL v){
x=(x+v)%MOD;
if(x<0)x+=MOD;
}
int main(){
build();
RI(N);
REPP(i,1,N){
DRII(x,y);
e[x].PB(y);e[y].PB(x);
}
dfs(1);
for(int i=1;i<=N;i+=R_R){
int two=1;
while(two<=min(i+R_R-1,N))two*=2;
memset(t,0,sizeof(int)*(two+1));
memset(s,0,sizeof(int)*(two+1));
int up=0;
for(int j=min(i+R_R-1,N);j>=i;j--){
up++;
for(int k=up;k>0;k--){
t[k]+=t[k-1];
if(t[k]>=MOD)t[k]-=MOD;
}
t[0]+=cnt[j];
while(up>0&&t[up]==0)up--;
}
REP(j,i+1)s[j]=C(i,j);
int n2=two;
up=two;
ntt(0,n2,s);
ntt(0,up,t);
mul(up,t,s);
ntt(1,up,t);
REP(i,n2)ADD(an[i],t[i]);
}
REPP(i,1,N+1){
an[i]=(N*C(N,i)%MOD-an[i])%MOD;
if(an[i]<0)an[i]+=MOD;
printf("%d\n",an[i]);
}
return 0;
}
Submission Info
Submission Time
2016-10-01 22:43:53+0900
Task
F - Many Easy Problems
User
dreamoon
Language
C++14 (GCC 5.4.1)
Score
1900
Code Size
3878 Byte
Status
AC
Exec Time
3957 ms
Memory
63104 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:116:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
RI(N);
^
./Main.cpp:118:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
DRII(x,y);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1900 / 1900
Status
Set Name
Test Cases
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
Case Name
Status
Exec Time
Memory
doublestar0
AC
2059 ms
51960 KB
doublestar1
AC
2057 ms
51960 KB
doublestar2
AC
2055 ms
52088 KB
doublestar3
AC
2045 ms
51960 KB
doublestar4
AC
2053 ms
51960 KB
example0
AC
53 ms
39296 KB
example1
AC
53 ms
39296 KB
example2
AC
53 ms
39296 KB
line0
AC
3957 ms
62848 KB
line1
AC
3944 ms
62848 KB
line2
AC
3956 ms
63104 KB
line3
AC
3946 ms
62848 KB
line4
AC
3941 ms
62848 KB
maxrand0
AC
2601 ms
51968 KB
maxrand1
AC
2570 ms
52096 KB
maxrand10
AC
2563 ms
52096 KB
maxrand11
AC
2500 ms
51968 KB
maxrand12
AC
2492 ms
51968 KB
maxrand13
AC
2584 ms
51968 KB
maxrand14
AC
2619 ms
51968 KB
maxrand15
AC
2599 ms
51968 KB
maxrand16
AC
2573 ms
51968 KB
maxrand17
AC
2604 ms
51968 KB
maxrand18
AC
2538 ms
51968 KB
maxrand19
AC
2524 ms
51968 KB
maxrand2
AC
2611 ms
51968 KB
maxrand3
AC
2595 ms
51968 KB
maxrand4
AC
2557 ms
51968 KB
maxrand5
AC
2558 ms
51968 KB
maxrand6
AC
2546 ms
51968 KB
maxrand7
AC
2536 ms
52096 KB
maxrand8
AC
2670 ms
51968 KB
maxrand9
AC
2681 ms
51968 KB
rand0
AC
71 ms
39552 KB
rand1
AC
53 ms
39296 KB
rand2
AC
63 ms
39424 KB
rand3
AC
69 ms
39552 KB
rand4
AC
55 ms
39424 KB
rand5
AC
69 ms
39552 KB
rand6
AC
61 ms
39424 KB
rand7
AC
69 ms
39552 KB
rand8
AC
54 ms
39296 KB
rand9
AC
57 ms
39424 KB
star0
AC
2050 ms
52340 KB
star1
AC
2025 ms
52340 KB
star2
AC
2074 ms
52340 KB
star3
AC
2046 ms
52340 KB
star4
AC
2041 ms
52340 KB