結果
| 問題 |
No.1621 Sequence Inversions
|
| コンテスト | |
| ユーザー |
dekomori_sanae
|
| 提出日時 | 2022-01-28 12:14:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,518 ms / 3,000 ms |
| コード長 | 1,981 bytes |
| コンパイル時間 | 1,971 ms |
| コンパイル使用メモリ | 98,800 KB |
| 実行使用メモリ | 417,536 KB |
| 最終ジャッジ日時 | 2024-12-28 09:25:52 |
| 合計ジャッジ時間 | 12,449 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 998244353;
const ll INF = 1e16;
int main() {
ll n, K;
cin >> n >> K;
map<ll, ll> mp;
rep(i, n) {
ll a;
cin >> a;
mp[a]++;
}
vector<vvl> P(K+1, vvl(n+1, vl(n+1))); // P[i][j][k] : iをj以下の数k個で表す場合の数
exrep(j, 0, n) {
exrep(k, 1, n) {
P[0][j][k] = 1;
}
}
exrep(i, 1, K) {
exrep(j, 1, n) {
exrep(k, 1, n) {
P[i][j][k] += P[i][j][k-1];
if(i - k >= 0) {
P[i][j][k] += P[i - k][j-1][k];
}
P[i][j][k] %= mod;
}
}
}
vvl dp(n+1, vl(K+1)); // dp[i][j] : i個挿入して、転倒数がjとなる場合の数
ll i = 0; // いままで並べた個数
for(auto p : mp) {
ll x = p.second; // いまから挿入する数の個数
if(i == 0) {
dp[x][0] = 1;
i += x;
continue;
}
exrep(j, 0, K) {
exrep(k, 0, min(K - j, i*x)) {
dp[i + x][j + k] += P[k][i][x] * dp[i][j];
dp[i + x][j + k] %= mod;
}
}
i += x;
}
out(dp[n][K]);
re0;
}
dekomori_sanae