提出 #41775072
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
const int md=998244353,N=600010,g3=(md+1)/3;
typedef long long LL;
int n,m,k,a[N],A[N],G[N],b[N],f[N];
inline void upd(int&a){a+=a>>31&md;}
inline int ksm(int a,int b){
int r=1;
for(;b;b>>=1,a=(LL)a*a%md)if(b&1)r=(LL)r*a%md;return r;
}
namespace poly{
int lim,rev[N],inv[N];
inline int poly_start(){
inv[1]=1;
for(int i=2;i<N;++i)inv[i]=(md-md/i)*(LL)inv[md%i]%md;
return 1;
}
int __START__=poly_start();
inline void init(int n){
int l=-1;
for(lim=1;lim<n;lim<<=1)++l;
for(int i=1;i<lim;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<l);
}
void NTT(int*a,int f){
for(int i=1;i<lim;++i)if(i<rev[i])std::swap(a[i],a[rev[i]]);
for(int i=1;i<lim;i<<=1){
const int gi=ksm(f?3:g3,(md-1)/(i<<1));
for(int j=0;j<lim;j+=i<<1)
for(int k=0,g=1;k<i;++k,g=(LL)g*gi%md){
const int x=a[j+k],y=a[j+k+i]*(LL)g%md;
upd(a[j+k]+=y-md),upd(a[j+k+i]=x-y);
}
}
if(!f){
const LL iv=inv[lim];
for(int i=0;i<lim;++i)a[i]=a[i]*iv%md;
}
}
void INV(const int*a,int*B,int n){
if(n==1)*B=ksm(*a,md-2);else{
INV(a,B,n+1>>1);
init(n<<1);
static int A[N];
for(int i=0;i<n;++i)A[i]=a[i];
for(int i=n;i<lim;++i)A[i]=0;
NTT(A,1),NTT(B,1);
for(int i=0;i<lim;++i)B[i]=B[i]*((2-(LL)A[i]*B[i]%md+md)%md)%md;
NTT(B,0);
for(int i=n;i<lim;++i)B[i]=0;
}
}
void dao(const int*a,int*G,int n){
G[n-1]=0;
for(int i=1;i<n;++i)
G[i-1]=(LL)i*a[i]%md;
}
void INT(const int*a,int*G,int n){
*G=0;
for(int i=n-1;~i;--i)G[i+1]=a[i]*(LL)inv[i+1]%md;
}
void LN(const int*a,int*B,int n){
static int F[N];
dao(a,F,n),INV(a,B,n);
init(n<<1);
for(int i=n;i<lim;++i)B[i]=F[i]=0;
NTT(F,1),NTT(B,1);
for(int i=0;i<lim;++i)F[i]=(LL)B[i]*F[i]%md;
NTT(F,0);
INT(F,B,n);
for(int i=n;i<lim;++i)B[i]=0;
}
void EXP(const int*a,int*F,int n){
if(n==1)*F=1;else{
EXP(a,F,n+1>>1);
static int F0[N],A[N];
for(int i=0;i<=n<<1;++i)F0[i]=0,A[i]=a[i];
LN(F,F0,n);
init(n<<1);
for(int i=n;i<lim;++i)A[i]=0;
NTT(A,1),NTT(F0,1),NTT(F,1);
for(int i=0;i<lim;++i)F[i]=F[i]*(A[i]+1LL-F0[i]+md)%md;
NTT(F,0);
for(int i=n;i<lim;++i)F[i]=0;
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;f[0]=1;
for(int i=1;i<=n;i++)f[i]=1ll*f[i-1]*i%md;
for(int i=0;i<m;i++)cin>>b[i],a[b[i]-1]=ksm(f[b[i]-1],md-2);
poly::LN(a,A,n);
for(int i=0;i<n;++i)A[i]=A[i]*(LL)n%md;
for(int i=0;i<n;++i)a[i]=0;
poly::EXP(A,a,n);
cout<<1ll*a[n-2]*f[n-2]%md<<'\n';
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘int ksm(int, int)’:
./Main.cpp:9:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
9 | for(;b;b>>=1,a=(LL)a*a%md)if(b&1)r=(LL)r*a%md;return r;
| ^~~
./Main.cpp:9:48: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
9 | for(;b;b>>=1,a=(LL)a*a%md)if(b&1)r=(LL)r*a%md;return r;
| ^~~~~~
./Main.cpp: In function ‘void poly::INV(const int*, int*, int)’:
./Main.cpp:41:13: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
41 | INV(a,B,n+1>>1);
| ~^~
./Main.cpp: In function ‘void poly::EXP(const int*, int*, int)’:
./Main.cpp:74:13: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
74 | EXP(a,F,n+1>>1);
| ~^~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
600 / 600 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_01.txt |
AC |
11 ms |
5888 KiB |
| 00_sample_02.txt |
AC |
11 ms |
5836 KiB |
| 00_sample_03.txt |
AC |
12 ms |
5908 KiB |
| 01_test_01.txt |
AC |
11 ms |
5948 KiB |
| 01_test_02.txt |
AC |
832 ms |
21020 KiB |
| 01_test_03.txt |
AC |
867 ms |
21904 KiB |
| 01_test_04.txt |
AC |
828 ms |
21108 KiB |
| 01_test_05.txt |
AC |
833 ms |
21060 KiB |
| 01_test_06.txt |
AC |
865 ms |
21812 KiB |
| 01_test_07.txt |
AC |
869 ms |
21796 KiB |
| 01_test_08.txt |
AC |
868 ms |
21904 KiB |
| 01_test_09.txt |
AC |
850 ms |
21416 KiB |
| 01_test_10.txt |
AC |
849 ms |
21384 KiB |
| 01_test_11.txt |
AC |
836 ms |
21160 KiB |
| 01_test_12.txt |
AC |
846 ms |
21312 KiB |
| 01_test_13.txt |
AC |
834 ms |
21184 KiB |
| 01_test_14.txt |
AC |
865 ms |
21880 KiB |