結果

問題 No.2635 MST on Line++ 2
ユーザー 👑 potato167potato167
提出日時 2024-02-11 16:07:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,568 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 210,860 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-15 23:13:11
合計ジャッジ時間 7,724 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 33 ms
6,676 KB
testcase_05 RE -
testcase_06 AC 59 ms
6,676 KB
testcase_07 RE -
testcase_08 AC 37 ms
6,676 KB
testcase_09 RE -
testcase_10 AC 78 ms
6,676 KB
testcase_11 RE -
testcase_12 AC 89 ms
6,676 KB
testcase_13 RE -
testcase_14 AC 57 ms
6,676 KB
testcase_15 RE -
testcase_16 AC 62 ms
6,676 KB
testcase_17 RE -
testcase_18 AC 37 ms
6,676 KB
testcase_19 RE -
testcase_20 AC 31 ms
6,676 KB
testcase_21 RE -
testcase_22 AC 99 ms
6,676 KB
testcase_23 RE -
testcase_24 AC 23 ms
6,676 KB
testcase_25 AC 21 ms
6,676 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 20 ms
6,676 KB
testcase_30 AC 13 ms
6,676 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
struct mint{
    static constexpr int  m = 998244353;
    int x;
    mint() : x(0){}
    mint(ll x_):x(x_%m){if(x<0)x+=m;}
    mint &operator+=(mint b){if((x+=b.x)>=m)x-=m; return *this;}
    mint &operator-=(mint b){if((x-=b.x)<0)x+=m; return *this;}
    mint &operator*=(mint b){x=ll(x)*b.x%m; return *this;}
    mint pow(ll e) const {
        mint r = 1,b =*this;
        while(e){
            if(e&1) r*=b;
            b*=b;
            e>>=1;
        }
        return r;
    }
    mint inv(){return pow(m-2);}
    mint &operator/=(mint b){return *this*=b.pow(m-2);}
    friend mint operator+(mint a,mint b){return a+=b;}
    friend mint operator-(mint a,mint b){return a-=b;}
    friend mint operator/(mint a,mint b){return a/=b;}
    friend mint operator*(mint a,mint b){return a*=b;}
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N,K;
	cin>>N>>K;
	vector<ll> A(N);
	rep(i,0,N) cin>>A[i];
	assert(N<=7000);
	sort(A.begin(),A.end());
	auto D=A;
	for(int i=N-1;i>0;i--) D[i]-=D[i-1];
	vector<mint> fact(N+1,1),fact_inv(N+1,1);
	rep(i,0,N) fact[i+1]=fact[i]*(i+1);
	fact_inv[N]=fact[N].inv();
	for(int i=N;i>0;i--) fact_inv[i-1]=fact_inv[i]*i;
	auto P=[&](ll a,ll b) -> mint {
		if(a<b||a<0) return 0;
		return fact[a]*fact_inv[a-b];
	};
	mint ans=0;
	rep(i,0,N-1){
		int a=0;
		rep(j,0,N){
			if(K<=min(abs(j-i),abs(j-i-1))) a++;
		}
		rep(j,0,N){
			ans+=P(a,j)*fact[N-j]*mint(D[j]);
		}
	}
	cout<<ans.x<<"\n";
}
0