题解:AT_agc054_c [AGC054C] Roughly Sorted
提供一个
考虑一个排列如何用最小操作步数变得合法,我们先看
现在给定了最终的排列,如果点
代码如下(AT上已过)
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+10,mod=998244353;
int n,k,a[N],ans=1,v[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i],v[a[i]]=i;
for(int i=1;i<=n;i++)if(v[i]==i+k)ans=ans*(n-i-k+1)%mod;
cout<<ans;
return 0;
}