結果

問題 No.1670 Many Gacha
ユーザー HIcoder
提出日時 2023-07-05 15:45:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 102,596 KB
最終ジャッジ日時 2025-02-15 06:15:19
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;


ll mod_pow(ll x,ll y,ll mod){
    ll res=1;

    while(y>0){
        if(y&1){
            res*=x;
            res%=mod;
        }
        x*=x;
        x%=mod;
        y/=2;
    }

    return res;
}

int main(){
    int N,M;
    cin>>N>>M;
    vector<ll> A(M+1),Ap(N+1,INF);
    for(int i=1;i<=M;i++){
        cin>>A[i];
    }

    multiset<ll> mst;

    for(int i=M;i>=1;i--){
        mst.insert(A[i]);
    }
    for(int i=1;i<=N;i++){
        auto it=mst.lower_bound(i);//i以上となる最小の値
        Ap[i]=*it;
    }

vector<ll> p(N+1,0);
ll ans=0;
    for(int i=N;i>=1;i--){
        ll inv=mod_pow(N-i+1,MOD-2,MOD);
        p[i]=inv;
    }
    for(int i=N;i>=1;i--){
        ans+=p[i]*Ap[i]%MOD;
        ans%=MOD;
    }

    cout<<ans<<endl;

}
0