QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#799665 | #9839. Selection Sort Count | rotcar07 | WA | 1ms | 5720kb | C++23 | 645b | 2024-12-05 16:56:20 | 2024-12-05 16:56:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
constexpr int maxn=2e5+5;
typedef long long ll;
constexpr ll mod=998244353;
ll fac[maxn],inv[maxn];
ll qpow(ll a,int b){
ll ans=1;
while(b){
if(b&1) ans=ans*a%mod;
a=a*a%mod,b>>=1;
}
return ans;
}int a[maxn];
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<n;i++) cin>>a[i];
for(int i=fac[0]=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
inv[n]=qpow(fac[n],mod-2);
for(int i=n;i>=1;i--) inv[i-1]=inv[i]*i%mod;
ll ans=1;
for(int i=1;i<n;i++) ans=ans*fac[a[i]+1]%mod*inv[a[i+1]]%mod*inv[a[i]+1-a[i+1]]%mod;
cout<<ans<<'\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5720kb
input:
3 1 1
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5648kb
input:
6 0 1 1 1 0
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
6 0 1 2 1 1
output:
6
result:
ok single line: '6'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5656kb
input:
8 3 3 2 1 2 1 1
output:
432
result:
wrong answer 1st lines differ - expected: '24', found: '432'