結果

問題 No.1621 Sequence Inversions
ユーザー 沙耶花沙耶花
提出日時 2021-07-22 22:04:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,001 ms / 3,000 ms
コード長 1,122 bytes
コンパイル時間 4,944 ms
コンパイル使用メモリ 270,456 KB
実行使用メモリ 216,156 KB
最終ジャッジ日時 2023-09-24 17:05:06
合計ジャッジ時間 13,317 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
203,444 KB
testcase_01 AC 108 ms
203,400 KB
testcase_02 AC 108 ms
203,596 KB
testcase_03 AC 108 ms
203,404 KB
testcase_04 AC 109 ms
203,444 KB
testcase_05 AC 109 ms
203,432 KB
testcase_06 AC 108 ms
203,792 KB
testcase_07 AC 121 ms
205,224 KB
testcase_08 AC 344 ms
213,004 KB
testcase_09 AC 871 ms
215,988 KB
testcase_10 AC 2,001 ms
216,156 KB
testcase_11 AC 376 ms
213,020 KB
testcase_12 AC 306 ms
208,708 KB
testcase_13 AC 203 ms
206,868 KB
testcase_14 AC 117 ms
204,796 KB
testcase_15 AC 114 ms
204,284 KB
testcase_16 AC 131 ms
204,448 KB
testcase_17 AC 157 ms
204,784 KB
testcase_18 AC 132 ms
204,428 KB
testcase_19 AC 111 ms
203,564 KB
testcase_20 AC 124 ms
204,156 KB
testcase_21 AC 158 ms
204,816 KB
testcase_22 AC 121 ms
204,400 KB
testcase_23 AC 158 ms
204,792 KB
testcase_24 AC 110 ms
203,536 KB
testcase_25 AC 110 ms
203,488 KB
testcase_26 AC 109 ms
203,508 KB
testcase_27 AC 109 ms
203,376 KB
testcase_28 AC 110 ms
203,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

mint memo[101][101][5001];
bool v[101][101][5001];
mint get(int x,int t,int k){
	if(x<0){
		if(t!=0||k!=0)return 0;
		return 1;
	}
	
	if(v[x][t][k])return memo[x][t][k];
	
	v[x][t][k] = true;
	mint ret = 0;
	rep(i,t+1){
		if(i*x>k)break;
		ret += get(x-1,t-i,k-i*x);
	}
	memo[x][t][k] = ret;
	return ret;
}

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> A(N);
	vector<int> t;
	rep(i,N){
		cin>>A[i];
		t.push_back(A[i]);
	}
	
	sort(t.begin(),t.end());
	
	t.erase(unique(t.begin(),t.end()),t.end());
	
	vector<int> cnt(t.size(),0);
	
	rep(i,N){
		int d = distance(t.begin(),lower_bound(t.begin(),t.end(),A[i]));
		cnt[d] ++;
	}
	
	vector<mint> dp(K+1,0);
	dp[0] = 1;
	int sum = 0;
	rep(i,t.size()){
		vector<mint> ndp(K+1,0);
		
		rep(j,K+1){
			ndp[j] = get(sum,cnt[i],j);
		}
		sum += cnt[i];
		dp = convolution(dp,ndp);
		while(dp.size()>K+1)dp.pop_back();
	}
	
	cout<<dp[K].val()<<endl;

	return 0;
}
0