QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209102 | #7558. Abstract | ucup-team870 | RE | 0ms | 0kb | C++14 | 4.0kb | 2023-10-10 10:05:18 | 2023-10-10 10:05:19 |
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=1e5+5,mod=998244353;
int n,cnt[6],a[6][N],num[6];
P q[N*5];
int cal(int i){
return n-cnt[i]-num[i];
}
int wk1(int v){
ll res=0;
rep(i1,1,5){
rep(i2,1,5){
if(i2==i1)continue;
rep(i3,1,5){
if(i3==i1 || i3==i2 || i3<i2)continue;
rep(i4,1,5){
if(i4==i1 || i4==i2 || i4==i3)continue;
rep(i5,1,5){
if(i5==i4 || i5==i3 || i5==i2 || i5==i1 || i5<i4)continue;
res=(res+1ll*cnt[i1]*num[i2]%mod*num[i3]%mod*cal(i4)%mod*cal(i5))%mod;
}
}
}
}
}
return res%mod;
}
int wk2(int v){
ll res=0;
rep(i1,1,5){
rep(i2,1,5){
if(i2<=i1)continue;
rep(i3,1,5){
if(i3==i1 || i3==i2)continue;
rep(i4,1,5){
if(i4==i1 || i4==i2 || i4<=i3)continue;
rep(i5,1,5){
if(i5==i4 || i5==i3 || i5==i2 || i5==i1)continue;
res=(res+1ll*cnt[i1]*cnt[i2]%mod*num[i3]%mod*num[i4]%mod*cal(i5))%mod;
res=(res+1ll*cnt[i1]*cnt[i2]%mod*cal(i3)%mod*cal(i4)%mod*num[i5])%mod;
}
}
}
}
}
return res%mod;
}
int wk3(int v){
ll res=0;
rep(i1,1,5){
rep(i2,1,5){
if(i2==i1)continue;
rep(i3,1,5){
if(i3<=i1 || i3<=i2)continue;
rep(i4,1,5){
if(i4==i1 || i4==i2 || i4==i3)continue;
rep(i5,1,5){
if(i5==i4 || i5==i3 || i5==i2 || i5==i1 || i5<i4)continue;
res=(res+1ll*cnt[i1]*cnt[i2]%mod*cnt[i3]%mod*(n-cnt[i4])%mod*(n-cnt[i5]))%mod;
}
}
}
}
}
}
int wk4(int v){
ll res=0;
rep(i1,1,5){
rep(i2,1,5){
if(i2==i1)continue;
rep(i3,1,5){
if(i3<=i1 || i3<=i2)continue;
rep(i4,1,5){
if(i4<=i1 || i4<=i2 || i4<=i3)continue;
rep(i5,1,5){
if(i5==i4 || i5==i3 || i5==i2 || i5==i1)continue;
res=(res+1ll*cnt[i1]*cnt[i2]%mod*cnt[i3]%mod*cnt[i4]%mod*(n-cnt[i5]))%mod;
}
}
}
}
}return res;
}
int wk5(int v){
ll res=0;
rep(i1,1,5){
rep(i2,1,5){
if(i2==i1)continue;
rep(i3,1,5){
if(i3<=i1 || i3<=i2)continue;
rep(i4,1,5){
if(i4<=i1 || i4<=i2 || i4<=i3)continue;
rep(i5,1,5){
if(i5<=i4 || i5<=i3 || i5<=i2 || i5<=i1)continue;
res=(res+1ll*cnt[i1]*cnt[i2]%mod*cnt[i3]%mod*cnt[i4]%mod*cnt[i5])%mod;
}
}
}
}
}return res;
}
int main() {
IOS
cin>>n; int top=0;
rep(j,1,5){
rep(i,1,n){
cin>>a[j][i]; q[++top]={a[j][i],j};
}
}
sort(q+1,q+top+1); q[top+1].first=-1;
ll ans=0;
rep(i,1,top){
int l=i; while(q[i].first==q[i+1].first)++i;
rep(j,l,i){
++cnt[q[j].second];
}
ll sum=0;
sum+=wk1(q[i].first);
sum+=wk2(q[i].first);
sum+=wk3(q[i].first);
sum+=wk4(q[i].first);
sum+=wk5(q[i].first);
rep(j,l,i){
++num[q[j].second];
}
cout<<sum<<'\n';
ans+=sum*q[i].first%mod;
}
cout<<ans%mod;
return 0;
}
/*
3
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 2 1 1 1 1 2 2 3