QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#455047 | #8820. Exchanging Kubic 2 | 275307894a | RE | 0ms | 0kb | C++14 | 2.0kb | 2024-06-25 18:26:26 | 2024-06-25 18:26:27 |
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
#define all(x) x.begin(),x.end()
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=800+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
#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...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m,vis[N][N],k=1200;
ll dp[N][1205][2],f[N][1205][2];
void add(ll &x,ll y){(x+=y)>=mod&&(x-=mod);}
void Solve(){
int i,j;scanf("%d",&n);
for(i=1;i<=n;i++){
int len,x;scanf("%d",&len);
while(len--) scanf("%d",&x),vis[i][x]=1;
}
for(i=0;i<=k;i++) if(vis[1][i]) dp[i][1][0]=1;
for(i=2;i<=n;i++){
for(j=0;j<=k;j++) for(int h=0;h<=k;h++) for(int o:{0,1}) add(dp[j+1][h+1][o],dp[j][h][o]);
for(j=0;j<=k;j++) if(!vis[i][j]) Me(dp[j],0);
for(j=0;j<=k;j++) for(int h=0;h<=k;h++){
if(h<i){
for(int o:{0,1}) add(dp[j][i][o],dp[j][h][o]),dp[j][h][o]=0;
}
if(h>n+i-1){
// if(dp[j][h][0]) gdb(dp[j][h][0],i,h,n-i+1);
add(dp[j][n+i-1][1],dp[j][h][0]*(h-(n+i-1))%mod);
for(int o:{0,1}) add(dp[j][n+i-1][o],dp[j][h][o]),dp[j][h][o]=0;
}
}
}
ll ans=0;
for(i=0;i<=k;i++) for(j=0;j<=k;j++) ans+=dp[i][j][1];
printf("%lld\n",(ans%mod+mod)%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: 0
Runtime Error
input:
5 3 1 2 3 1 2 0 4 0 2 3 4 2 2 3