結果

問題 No.1621 Sequence Inversions
ユーザー nok0nok0
提出日時 2021-07-06 09:38:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 571 ms / 3,000 ms
コード長 1,182 bytes
コンパイル時間 4,570 ms
コンパイル使用メモリ 273,968 KB
実行使用メモリ 204,444 KB
最終ジャッジ日時 2023-09-24 15:03:01
合計ジャッジ時間 12,030 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
202,920 KB
testcase_01 AC 99 ms
202,636 KB
testcase_02 AC 98 ms
202,788 KB
testcase_03 AC 98 ms
202,716 KB
testcase_04 AC 102 ms
202,960 KB
testcase_05 AC 98 ms
202,800 KB
testcase_06 AC 100 ms
202,836 KB
testcase_07 AC 102 ms
202,740 KB
testcase_08 AC 211 ms
203,140 KB
testcase_09 AC 203 ms
203,224 KB
testcase_10 AC 314 ms
204,396 KB
testcase_11 AC 226 ms
203,044 KB
testcase_12 AC 523 ms
204,444 KB
testcase_13 AC 571 ms
204,316 KB
testcase_14 AC 167 ms
202,960 KB
testcase_15 AC 146 ms
202,880 KB
testcase_16 AC 250 ms
203,108 KB
testcase_17 AC 387 ms
203,588 KB
testcase_18 AC 239 ms
202,792 KB
testcase_19 AC 99 ms
202,680 KB
testcase_20 AC 160 ms
202,844 KB
testcase_21 AC 428 ms
203,636 KB
testcase_22 AC 181 ms
202,948 KB
testcase_23 AC 493 ms
203,848 KB
testcase_24 AC 100 ms
202,692 KB
testcase_25 AC 100 ms
202,644 KB
testcase_26 AC 99 ms
202,708 KB
testcase_27 AC 100 ms
202,644 KB
testcase_28 AC 100 ms
202,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint998244353;
using T = tuple<int, int, int>;

mint memo[101][5001][101];
int main() {
	for(int i = 0; i <= 100; i++)
		for(int j = 0; j <= 5000; j++)
			for(int k = 0; k <= 100; k++)
				memo[i][j][k] = -1;

	auto f = [&](auto f, int n, int m, int k) {
		if(memo[n][m][k] != -1) return memo[n][m][k];
		if(m < 0 or k < 0 or n * k < m) return memo[n][m][k] = 0;
		if(n == 0) return memo[n][m][k] = !m;
		return memo[n][m][k] = f(f, n - 1, m, k) + f(f, n, m - n, k - 1);
	};

	int n, k;
	cin >> n >> k;
	vector a(n, 0), cnt(n, 0);
	for(auto& v : a) cin >> v;

	if(k > n * (n - 1) / 2) {
		puts("0");
		return 0;
	}

	sort(a.begin(), a.end());
	int now = 0;
	for(int i = 0; i < n - 1; i++) {
		cnt[now]++;
		if(a[i] != a[i + 1]) now++;
	}
	cnt[now]++;

	vector dp(n + 1, vector(k + 1, mint(0)));
	dp[0][0] = 1;
	int cum = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= k; j++)
			for(int l = 0; l <= min(cnt[i] * cum, j); l++)
				dp[i + 1][j] += dp[i][j - l] * f(f, cnt[i], l, cum);
		cum += cnt[i];
	}

	cout << dp.back()[k].val() << '\n';

	return 0;
}
0