結果

問題 No.1621 Sequence Inversions
ユーザー nok0nok0
提出日時 2021-07-06 09:34:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,069 bytes
コンパイル時間 4,946 ms
コンパイル使用メモリ 283,332 KB
実行使用メモリ 68,204 KB
最終ジャッジ日時 2023-09-24 15:02:47
合計ジャッジ時間 14,477 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 49 ms
5,760 KB
testcase_08 TLE -
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main() {
	map<T, mint> memo;
	auto f = [&](auto f, int n, int m, int k) {
		if(memo.count(T(n, m, k))) return memo[T(n, m, k)];
		if(n == 0 or m < 0) return memo[T(n, m, k)] = (m ? 0 : 1);
		if(n * k < m) return memo[T(n, m, k)] = 0;
		return memo[T(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