QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#333978 | #8180. Bridge Elimination | 275307894a# | WA | 76ms | 9780kb | C++14 | 2.6kb | 2024-02-20 22:10:54 | 2024-02-20 22:10:55 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=400+5,M=N*N+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
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;
int n,A[N];
ll pw[N*N],frc[N],inv[N],f[N],g[N],C[N][N];
void init1(){
for(int i=1;i<=n;i++){
f[i]=pw[i*(i-1)/2];
for(int j=1;j<i;j++) f[i]-=C[i-1][j-1]*f[j]%mod*pw[(i-j)*(i-j-1)/2]%mod;
f[i]=(f[i]%mod+mod)%mod;
// gdb(f[i]);
}
}
void init2(){
static ll dp[N][N];
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int h=1;h<=i;h++){
for(int j=1;j<=i;j++) dp[i][h]=(dp[i][h]+dp[i-j][h-1]*C[i-1][j-1]%mod*f[j]%mod*j)%mod;
}
}
for(int i=1;i<=n;i++){
g[i]=f[i];
for(int j=1;j<i;j++){
ll pw=1,tot=0;
for(int h=1;h<=i-j;h++) pw=pw*j%mod,tot+=pw*dp[i-j][h];
g[i]-=g[j]*C[i-1][j-1]%mod*(tot%mod)%mod;
}
g[i]=(g[i]%mod+mod)%mod;
// gdb(g[i]);
}
}
ll dp[N][N],s[N][N];
void Solve(){
int i,j,h;scanf("%d",&n);
for(i=0;i<=n;i++) for(C[i][0]=j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
for(pw[0]=i=1;i<=n*n;i++) pw[i]=pw[i-1]*2%mod;
inv[1]=1;for(i=2;i<=n;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
for(frc[0]=inv[0]=i=1;i<=n;i++) frc[i]=frc[i-1]*i%mod,inv[i]=inv[i-1]*inv[i]%mod;
init1();
init2();
for(i=1;i<=n;i++) scanf("%d",&A[i]);
dp[0][0]=1;
for(i=1;i<=n;i++){
for(j=i;j<=n;j++){
for(h=1;h<=j;h++) dp[i][j]+=dp[i-1][j-h]*g[h]%mod*inv[h-1]%mod*h%mod;
dp[i][j]%=mod;
}
}
s[0][0]=1;
for(i=1;i<=n;i++){
for(j=0;j<=n;j++){
s[i][j]=s[i-1][j];
if(j) s[i][j]=(s[i][j]+s[i-1][j-1]*A[i])%mod;
}
}
ll tot=0;
for(i=1;i<=n;i++){
ll w=dp[i][n]*frc[n-i]%mod;//gdb(dp[i][n]*frc[n-i]%mod);
if(i==1) w=w*frc[n-1]%mod*inv[n]%mod;
else for(int j=1;j<i-1;j++) w=w*n%mod;
tot+=w*s[n][i]%mod;
}
printf("%lld\n",tot%mod);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8040kb
input:
3 8 5 9
output:
1102
result:
ok "1102"
Test #2:
score: 0
Accepted
time: 0ms
memory: 6124kb
input:
5 4 2 1 3 10
output:
63860
result:
ok "63860"
Test #3:
score: 0
Accepted
time: 0ms
memory: 8016kb
input:
7 229520041 118275986 281963154 784360383 478705114 655222915 970715006
output:
35376232
result:
ok "35376232"
Test #4:
score: -100
Wrong Answer
time: 76ms
memory: 9780kb
input:
300 7 8 2 8 6 5 5 3 2 3 8 0 6 0 1 0 10 7 10 0 1 0 6 7 2 6 4 7 9 4 6 5 5 9 8 5 4 5 3 5 4 4 10 2 4 9 7 5 2 2 5 6 3 6 8 2 8 3 6 2 5 1 10 3 0 7 1 9 6 5 10 0 3 0 2 4 2 7 6 10 1 0 0 9 4 3 5 5 2 6 1 8 5 4 0 0 5 8 8 1 3 9 9 9 8 1 4 10 7 4 8 5 0 4 3 4 4 8 1 6 1 10 9 3 2 5 0 0 5 2 7 5 4 10 3 5 10 10 7 6 10 3 ...
output:
808291760
result:
wrong answer 1st words differ - expected: '409590176', found: '808291760'