結果

問題 No.1621 Sequence Inversions
ユーザー shiomusubi496shiomusubi496
提出日時 2021-07-22 22:12:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 436 ms / 3,000 ms
コード長 1,150 bytes
コンパイル時間 5,334 ms
コンパイル使用メモリ 280,096 KB
実行使用メモリ 109,680 KB
最終ジャッジ日時 2023-09-24 17:17:21
合計ジャッジ時間 9,304 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 5 ms
6,060 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 4 ms
5,072 KB
testcase_08 AC 83 ms
34,364 KB
testcase_09 AC 76 ms
56,752 KB
testcase_10 AC 149 ms
109,680 KB
testcase_11 AC 90 ms
37,444 KB
testcase_12 AC 284 ms
48,112 KB
testcase_13 AC 348 ms
32,516 KB
testcase_14 AC 43 ms
5,440 KB
testcase_15 AC 40 ms
4,520 KB
testcase_16 AC 138 ms
7,692 KB
testcase_17 AC 316 ms
12,076 KB
testcase_18 AC 135 ms
7,608 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 59 ms
5,876 KB
testcase_21 AC 366 ms
13,152 KB
testcase_22 AC 70 ms
5,504 KB
testcase_23 AC 436 ms
15,176 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define int long long
using namespace std;
constexpr int mod=998244353;
signed main(){
    int N,K; cin>>N>>K;
    map<int,int> mp;
    for(int i=0;i<N;i++){
        int a; cin>>a;
        mp[a]++;
    }
    int M=mp.size();
    vector<vector<int>> dp(N+1,vector<int>(K+1));
    dp[0][0]=1;
    int sum=0;
    vector<int> B;
    for(auto[a,b]:mp)B.push_back(b);
    reverse(B.begin(),B.end());
    for(int b:B){
        vector<vector<vector<int>>> dp2(b+1,vector<vector<int>>(sum+1,vector<int>(K+1)));
        dp2[0][0][0]=1;
        for(int i=0;i<b;i++){
            for(int j=0;j<=sum;j++){
                for(int k=0;k<=K;k++){
                    if(k+j<=K)(dp2[i+1][j][k+j]+=dp2[i][j][k])%=mod;
                    if(j && k+1<=K)(dp2[i+1][j][k+1]+=dp2[i+1][j-1][k])%=mod;
                }
            }
        }
        vector<int> A(K+1);
        for(int i=0;i<=K;i++){
            for(int j=0;j<=sum;j++)(A[i]+=dp2[b][j][i])%=mod;
        }
        vector<int> C=atcoder::convolution(A,dp[sum]);
        for(int i=0;i<=K;i++)dp[sum+b][i]=C[i];
        sum+=b;
    }
    cout<<dp[N][K]<<endl;
}
0