QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275817 | #5274. IQ Game | qzzyq | RE | 0ms | 0kb | C++14 | 1.8kb | 2023-12-05 08:36:21 | 2023-12-05 08:36:22 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define maxn 505
#define put() putchar('\n')
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
using namespace std;
Tp void read(T &x){
int f=1;x=0;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
x*=f;
}
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=998244353;
int power(int x,int y=mod-2) {
int sum=1;
while (y) {
if (y&1) sum=sum*x%mod;
x=x*x%mod;y>>=1;
}
return sum;
}
int n,m,k,ans;
int a[maxn],c[maxn][maxn],f[maxn][maxn];
signed main(void){
// freopen("1.in","r",stdin);
freopen("pitfall.in","r",stdin);
freopen("pitfall.out","w",stdout);
int i,j,l;
read(n);read(m);read(k);
for (i=1;i<=m;i++) read(a[i]),a[i]=(a[i]-k+n)%n,a[i]=(n-a[i])%n;
for (i=0;i<=m;i++) {
c[i][0]=1;
for (j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
sort(a+1,a+1+m);
a[m+1]=n;f[0][0]=1;
int invn=power(n);
// for (i=1;i<=m;i++) gdb(i,a[i]);
for (i=1;i<=m;i++) {
int len=a[i+1]-a[i];
// gdb(i,a[i],a[i+1],len);
for (j=0;j<i;j++) {
int tmp=1,w=len*invn%mod;
for (l=0;l<=j;l++) {
// gdb(i,j,l,c[j][l]);
f[i][j]=(f[i][j]+f[i-1][j-l]*tmp%mod*c[j][l])%mod;
tmp=tmp*w%mod;
}
if (i==m)
ans=(ans+f[i][j])%mod;//,gdb(i,j,f[i][j]);
}
}
printf("%lld\n",ans);
return 0;
}
//i=begin && g++ $i.cpp -o $i -std=c++14 && ./$i
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
3 2 3 2 3