結果

問題 No.1621 Sequence Inversions
ユーザー siro53siro53
提出日時 2021-07-23 09:39:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 381 ms / 3,000 ms
コード長 3,350 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 208,288 KB
実行使用メモリ 406,096 KB
最終ジャッジ日時 2023-09-25 07:34:21
合計ジャッジ時間 10,392 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
405,804 KB
testcase_01 AC 381 ms
405,840 KB
testcase_02 AC 227 ms
405,812 KB
testcase_03 AC 178 ms
405,816 KB
testcase_04 AC 182 ms
405,848 KB
testcase_05 AC 172 ms
405,844 KB
testcase_06 AC 173 ms
405,912 KB
testcase_07 AC 172 ms
405,836 KB
testcase_08 AC 186 ms
406,048 KB
testcase_09 AC 181 ms
405,852 KB
testcase_10 AC 203 ms
405,928 KB
testcase_11 AC 192 ms
405,956 KB
testcase_12 AC 240 ms
405,908 KB
testcase_13 AC 249 ms
405,844 KB
testcase_14 AC 184 ms
406,096 KB
testcase_15 AC 179 ms
405,792 KB
testcase_16 AC 194 ms
405,912 KB
testcase_17 AC 217 ms
405,836 KB
testcase_18 AC 196 ms
405,836 KB
testcase_19 AC 171 ms
405,856 KB
testcase_20 AC 184 ms
405,880 KB
testcase_21 AC 224 ms
405,808 KB
testcase_22 AC 185 ms
405,852 KB
testcase_23 AC 235 ms
405,856 KB
testcase_24 AC 173 ms
405,972 KB
testcase_25 AC 171 ms
405,808 KB
testcase_26 AC 174 ms
405,824 KB
testcase_27 AC 173 ms
405,976 KB
testcase_28 AC 174 ms
405,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "f.cpp"
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void Case(int i) { cout << "Case #" << i << ": "; }
int popcount(int x) { return __builtin_popcount(x); }
ll popcount(ll x) { return __builtin_popcountll(x); }
#pragma endregion Macros

#line 1 "/home/siro53/kyo-pro/compro_library/data_structure/compress.hpp"
template <typename T> struct Compress {
    vector<T> v;
    Compress() {}
    Compress(vector<T> vv) : v(vv) {
        sort(ALL(v));
        v.erase(unique(ALL(v)), end(v));
    }
    void build(vector<T> vv) {
        v = vv;
        sort(ALL(v));
        v.erase(unique(ALL(v)), end(v));
    }
    int get(T x) { return (int)(lower_bound(ALL(v), x) - v.begin()); }
    T &operator[](int i) { return v[i]; }
    size_t size() { return v.size(); }
};
#line 72 "f.cpp"

#include <atcoder/modint>
using mint = atcoder::modint998244353;

mint dp[101][10001];
mint f[101][101][10001];

void init() {
    REP(i, 101) f[0][i][0] = 1;
    FOR(n, 1, 101) REP(k, 101) REP(m, 10001) {
        if(n * k < m) break;
        f[n][k][m] += f[n-1][k][m];
        if(m - n >= 0 and k > 0) f[n][k][m] += f[n][k-1][m-n];
    }
}

int main() {
    init();
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    sort(ALL(a));
    Compress<int> comp(a);
    int sz = comp.size();

    // cnt[i] = iの個数
    vector<int> cnt(sz, 0);
    REP(i, N) cnt[comp.get(a[i])]++;
    vector<int> sum(sz+1, 0);
    REP(i, sz) sum[i+1] = sum[i] + cnt[i];

    dp[0][0] = 1;
    FOR(i, 1, sz+1) {
        REP(k, K+1) {
            REP(j, sum[i-1]*cnt[i-1]+1) {
                if(k - j < 0) break;
                dp[i][k] += f[cnt[i-1]][sum[i-1]][j] * dp[i-1][k-j];
            }
        }
    }
    cout << dp[sz][K].val() << endl;
}
0