結果

問題 No.1621 Sequence Inversions
ユーザー kwm_tkwm_t
提出日時 2021-07-23 00:23:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 416 ms / 3,000 ms
コード長 1,629 bytes
コンパイル時間 4,886 ms
コンパイル使用メモリ 236,792 KB
実行使用メモリ 204,516 KB
最終ジャッジ日時 2023-09-24 21:15:56
合計ジャッジ時間 15,401 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
203,064 KB
testcase_01 AC 272 ms
202,896 KB
testcase_02 AC 251 ms
203,308 KB
testcase_03 AC 244 ms
202,984 KB
testcase_04 AC 245 ms
202,916 KB
testcase_05 AC 245 ms
202,908 KB
testcase_06 AC 247 ms
202,992 KB
testcase_07 AC 250 ms
203,000 KB
testcase_08 AC 342 ms
202,980 KB
testcase_09 AC 282 ms
202,992 KB
testcase_10 AC 281 ms
203,000 KB
testcase_11 AC 338 ms
203,100 KB
testcase_12 AC 389 ms
203,216 KB
testcase_13 AC 411 ms
203,072 KB
testcase_14 AC 416 ms
203,488 KB
testcase_15 AC 395 ms
204,516 KB
testcase_16 AC 368 ms
204,496 KB
testcase_17 AC 394 ms
204,360 KB
testcase_18 AC 362 ms
204,180 KB
testcase_19 AC 251 ms
203,108 KB
testcase_20 AC 297 ms
203,908 KB
testcase_21 AC 396 ms
204,376 KB
testcase_22 AC 396 ms
204,436 KB
testcase_23 AC 395 ms
204,512 KB
testcase_24 AC 246 ms
203,052 KB
testcase_25 AC 245 ms
203,056 KB
testcase_26 AC 244 ms
202,904 KB
testcase_27 AC 245 ms
202,932 KB
testcase_28 AC 245 ms
203,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
mint subdp[101][101][5005];
void calc() {
	subdp[0][0][0] = 1;
	rep(i, 101)rep(j, 101)rep(k, 5001) {
		if ((j >= 1) && (k >= i))subdp[i][j][k] += subdp[i][j - 1][k - i];
		if (i >= 1)subdp[i][j][k] += subdp[i - 1][j][k];
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k; cin >> n >> k;
	map<int, int>mp;
	rep(i, n) {
		int a; cin >> a;
		mp[a]++;
	}
	vector<int>va;
	for (auto p : mp) va.push_back(p.second);
	vector<vector<mint>> dp(va.size() + 1, vector<mint>(5000, 0));
	dp[0][0] = 1;
	int sum = 0;
	calc();
	rep(i, va.size()) {
		rep(j, 5000) {
			rep(k, sum*va[i] + 1) {
				if (j + k >= 5000)continue;
				dp[i + 1][j + k] += dp[i][j] * subdp[sum][va[i]][k];
			}
		}
		sum += va[i];
	}
	cout << dp[va.size()][k].val() << endl;
	return 0;
}
0