Submission #6823284


Source Code Expand

Copy
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=3500;
int n,mod,a[N],inv[N],inv2[N],res[N];
int dp[N][N];
//
inline int add(int x,int y){x+=y;if(x>=mod)x-=mod;return x;}
inline int sub(int x,int y){x-=y;return (x<0)?x+mod:x;}
inline int mul(int x,int y){int ans=x*y;return ans%mod;}
inline int modpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
inline int modinv(int x){
	return modpow(x,mod-2);
}
int main(){
	n=getint();mod=n;
	rep(i,n)a[i]=getint();
	rep(i,N)inv[i]=modinv(i);
	rep(i,N)inv2[i]=modinv(sub(0,i));
	dp[n][0]=1;
	for(int i=n-1;i>=0;i--)for(int j=0;j<=n-i;j++){
		dp[i][j]=mul(dp[i+1][j],sub(0,i));
		if(j)dp[i][j]=add(dp[i][j],dp[i+1][j-1]);
		//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
	}
	rep(i,n)if(a[i]){
		int ans=1;
		rep(j,i)ans=mul(ans,inv[i-j]);
		for(int j=i+1;j<n;j++)ans=mul(ans,inv2[j-i]);
		int tmp=0;
		if(!i)tmp=dp[1][0];
		res[0]=add(res[0],mul(tmp,ans));
		for(int j=1;j<n;j++){
			tmp=mul(sub(dp[0][j],tmp),inv2[i]);
			if(!i)tmp=dp[1][j];
			res[j]=add(res[j],mul(tmp,ans));
		}
	}
	rep(i,n)printf("%d ",res[i]);
	return 0;
}

Submission Info

Submission Time
Task F - Polynomial Construction
User ruogu_alter
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1613 Byte
Status AC
Exec Time 208 ms
Memory 43392 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 43
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 29 ms 43264 KB
b08 AC 205 ms 43264 KB
b09 AC 205 ms 43264 KB
b10 AC 206 ms 43264 KB
b11 AC 29 ms 43264 KB
b12 AC 29 ms 43264 KB
b13 AC 117 ms 43264 KB
b14 AC 117 ms 43264 KB
b15 AC 54 ms 43264 KB
b16 AC 180 ms 43264 KB
b17 AC 118 ms 43264 KB
b18 AC 117 ms 43264 KB
b19 AC 115 ms 43392 KB
b20 AC 151 ms 43264 KB
b21 AC 188 ms 43264 KB
b22 AC 196 ms 43264 KB
b23 AC 204 ms 43264 KB
b24 AC 205 ms 43264 KB
b25 AC 208 ms 43392 KB
b26 AC 120 ms 43264 KB
b27 AC 83 ms 43264 KB
b28 AC 47 ms 43264 KB
b29 AC 39 ms 43264 KB
b30 AC 30 ms 43264 KB
b31 AC 30 ms 43264 KB
b32 AC 29 ms 43264 KB
b33 AC 1 ms 256 KB
b34 AC 1 ms 384 KB
b35 AC 101 ms 41216 KB
b36 AC 158 ms 41216 KB
b37 AC 54 ms 24320 KB
b38 AC 26 ms 32896 KB
b39 AC 2 ms 512 KB
b40 AC 41 ms 28672 KB
b41 AC 3 ms 3072 KB
b42 AC 15 ms 15872 KB
b43 AC 26 ms 33024 KB