結果

問題 No.1621 Sequence Inversions
ユーザー auauaauaua
提出日時 2021-07-22 23:12:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,956 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 173,376 KB
実行使用メモリ 7,012 KB
最終ジャッジ日時 2023-09-24 19:13:13
合計ジャッジ時間 3,068 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=1000010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;


//二分累乗



signed main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    vector<ll>cnt(n);
    vector<ll>re(n);

    ll la=0;
    rep(i,n){
        cnt[i]=lower_bound(all(a),a[i])-a.begin();
    }
    re[n-1]=1;
    for(int i=n-2;i>=0;i--){
        if(a[i]==a[i+1])re[i]=re[i+1]+1;
        else re[i]=1;
    }
    vector<vector<ll> >dp(n+1,vector<ll>(k+2));
    dp[0][0]=1;
    rep(i,n){
        if(i>0&&a[i]==a[i-1]){
            rep(j,k+1){
                dp[i+1][j]=dp[i][j];
            }
            continue;
        }
        ll c=cnt[i];
        ll ree=re[i];
        ll mi=min(c,ree);
        rep(j,k+1){
            ll u=min(k+1,j+c*ree+1);
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
            dp[i+1][u]=(dp[i+1][u]-dp[i][j])%mod;
        }
        rep(j,k+1){
            rep(l,mi-1){
                ll d=min(j+l+2,k+1);
                ll u=min(j+c*ree-1-l,k+1);
                dp[i+1][d]=(dp[i+1][d]+dp[i][j])%mod;
                dp[i+1][u]=(dp[i+1][u]-dp[i][j])%mod;
            }
        }
        REP(j,1,k+2){
            dp[i+1][j]=(dp[i+1][j]+dp[i+1][j-1])%mod;
        }
        la=i;
    }
    if(dp[n][k]<0)dp[n][k]+=mod;
    cout<<dp[n][k]<<endl;
}
0