結果

問題 No.1621 Sequence Inversions
ユーザー the-xin
提出日時 2021-07-30 12:48:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 606 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 70,292 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-09-15 08:21:29
合計ジャッジ時間 1,875 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 100+10,mod = 998244353;
typedef long long LL;
LL f[N][N*N];
int a[N];
int last[N];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int now=n;
	for(int i=n;i>=1;i--){
		while(a[now]!=a[i])now--;
		last[i]=now;//前面相同的数的个数 
	}
	f[1][0]=1;
	for(int i=2;i<=n;i++){
		for(int j=i;j>=1;j--){//增加 
			for(int k=i-j;k<=m;k++){
				f[i][k]+=f[i-1][k-(i-j+min((last[j]-j),i-j))];
				f[i][k]%=mod;
			}
		}
	}
	cout<<f[n][m];
	return 0;
}
0