結果

問題 No.1670 Many Gacha
ユーザー HIcoderHIcoder
提出日時 2023-07-05 15:45:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,059 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 105,640 KB
実行使用メモリ 17,024 KB
最終ジャッジ日時 2023-09-26 15:50:01
合計ジャッジ時間 7,305 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 165 ms
16,180 KB
testcase_09 AC 171 ms
16,756 KB
testcase_10 AC 165 ms
16,444 KB
testcase_11 AC 31 ms
5,676 KB
testcase_12 AC 33 ms
5,904 KB
testcase_13 AC 30 ms
5,780 KB
testcase_14 AC 124 ms
13,068 KB
testcase_15 AC 94 ms
10,532 KB
testcase_16 AC 113 ms
12,284 KB
testcase_17 AC 53 ms
7,804 KB
testcase_18 AC 96 ms
11,096 KB
testcase_19 AC 57 ms
7,788 KB
testcase_20 AC 148 ms
14,860 KB
testcase_21 AC 104 ms
11,528 KB
testcase_22 AC 106 ms
11,588 KB
testcase_23 AC 146 ms
14,596 KB
testcase_24 AC 78 ms
9,680 KB
testcase_25 AC 115 ms
12,224 KB
testcase_26 AC 58 ms
8,016 KB
testcase_27 AC 56 ms
7,636 KB
testcase_28 AC 49 ms
7,000 KB
testcase_29 AC 105 ms
12,028 KB
testcase_30 AC 65 ms
8,416 KB
testcase_31 AC 78 ms
9,316 KB
testcase_32 AC 60 ms
8,080 KB
testcase_33 AC 158 ms
15,768 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 36 ms
6,204 KB
testcase_36 AC 176 ms
17,024 KB
権限があれば一括ダウンロードができます

ソースコード

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