QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602498#7063. Space Stationzjy0001WA 5ms4604kbC++171.2kb2024-10-01 08:56:322024-10-01 08:56:33

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 08:56:33]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:4604kb
  • [2024-10-01 08:56:32]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=1e6+5,M=55,Mod=998244353;
int n,k,ans;
int a[M];
uLL val[N];
unordered_map<uLL,int>mp;
vector<int>frc({1,1}),inv({0,1}),ivf({1,1});
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
inline int qpow(int x,int y,int z=1){
	for(;y;(y>>=1)&&(x=(LL)x*x%Mod))if(y&1)z=(LL)z*x%Mod;return z;
}
inline void Init(const int&n){
	for(int i=frc.size();i<=n;++i)
		frc.emplace_back((LL)frc.back()*i%Mod),
		inv.emplace_back(Mod-Mod/i*(LL)inv[Mod%i]%Mod),
		ivf.emplace_back((LL)ivf.back()*inv.back()%Mod);
}
inline int solve(int r,int n,uLL s){
	if(r>49||!n)return frc[n];
	if(mp.count(s))return mp[s];
	int z=0;
	for(int i=1;i<=r;++i)if(a[i])
		--a[i],z=(z+(LL)solve(r+i,n-1,s^(val[i]*(a[i]+1))^(val[i]*a[i]))*(a[i]+1))%Mod,++a[i];
	return mp[s]=z;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
	cin>>n>>k,Init(n);
	for(int i=1;i<=n;++i){int x;cin>>x,++a[x];}
	uLL hs=0;
	for(int i=1;i<50;++i)val[i]=rng()*2+1,hs^=val[i]*a[i];
	int ans=solve(k,n-a[0],hs);
	ans=(LL)ans*frc[n]%Mod*ivf[n-a[0]]%Mod;
	cout<<ans<<'\n';
    return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

3
2 1 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

5
1 1 1 1 2 3

output:

54

result:

ok single line: '54'

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 4604kb

input:

100000
47 25 43 22 17 6 15 17 45 4 14 34 46 22 0 8 2 48 41 6 49 42 21 25 48 43 2 17 27 25 38 31 39 48 13 49 24 30 36 19 29 47 48 1 4 5 12 9 21 39 30 21 8 4 9 45 18 0 3 29 26 18 24 39 31 49 22 4 46 21 27 11 11 7 8 3 26 25 29 4 1 21 34 4 44 39 13 26 33 44 5 17 10 32 37 25 44 34 17 14 40 32 27 39 41 6 ...

output:

941391525

result:

wrong answer 1st lines differ - expected: '268605493', found: '941391525'