結果

問題 No.1387 Mitarushi's Remodeling
ユーザー chocoruskchocorusk
提出日時 2021-02-10 01:01:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 1,565 bytes
コンパイル時間 4,547 ms
コンパイル使用メモリ 195,812 KB
実行使用メモリ 34,828 KB
最終ジャッジ日時 2023-09-21 12:27:01
合計ジャッジ時間 37,573 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
21,140 KB
testcase_01 AC 9 ms
20,988 KB
testcase_02 AC 8 ms
21,032 KB
testcase_03 AC 8 ms
21,040 KB
testcase_04 AC 8 ms
20,928 KB
testcase_05 AC 8 ms
20,920 KB
testcase_06 AC 8 ms
21,028 KB
testcase_07 AC 8 ms
21,024 KB
testcase_08 AC 15 ms
21,332 KB
testcase_09 AC 17 ms
21,212 KB
testcase_10 AC 15 ms
21,104 KB
testcase_11 AC 15 ms
21,080 KB
testcase_12 AC 16 ms
21,204 KB
testcase_13 AC 15 ms
21,088 KB
testcase_14 AC 350 ms
34,604 KB
testcase_15 AC 354 ms
34,668 KB
testcase_16 AC 349 ms
34,692 KB
testcase_17 AC 347 ms
34,692 KB
testcase_18 AC 353 ms
34,584 KB
testcase_19 AC 354 ms
34,624 KB
testcase_20 AC 349 ms
34,664 KB
testcase_21 AC 350 ms
34,692 KB
testcase_22 AC 349 ms
34,564 KB
testcase_23 AC 354 ms
34,560 KB
testcase_24 AC 349 ms
34,696 KB
testcase_25 AC 347 ms
34,508 KB
testcase_26 AC 349 ms
34,696 KB
testcase_27 AC 350 ms
34,584 KB
testcase_28 AC 349 ms
34,692 KB
testcase_29 AC 349 ms
34,556 KB
testcase_30 AC 349 ms
34,584 KB
testcase_31 AC 354 ms
34,688 KB
testcase_32 AC 349 ms
34,624 KB
testcase_33 AC 348 ms
34,668 KB
testcase_34 AC 349 ms
34,516 KB
testcase_35 AC 349 ms
34,520 KB
testcase_36 AC 349 ms
34,516 KB
testcase_37 AC 350 ms
34,592 KB
testcase_38 AC 348 ms
34,628 KB
testcase_39 AC 348 ms
34,564 KB
testcase_40 AC 350 ms
34,672 KB
testcase_41 AC 349 ms
34,568 KB
testcase_42 AC 350 ms
34,556 KB
testcase_43 AC 347 ms
34,668 KB
testcase_44 AC 349 ms
34,688 KB
testcase_45 AC 349 ms
34,564 KB
testcase_46 AC 349 ms
34,504 KB
testcase_47 AC 346 ms
34,508 KB
testcase_48 AC 348 ms
34,736 KB
testcase_49 AC 347 ms
34,600 KB
testcase_50 AC 348 ms
34,704 KB
testcase_51 AC 348 ms
34,516 KB
testcase_52 AC 347 ms
34,520 KB
testcase_53 AC 350 ms
34,560 KB
testcase_54 AC 349 ms
34,664 KB
testcase_55 AC 349 ms
34,568 KB
testcase_56 AC 352 ms
34,676 KB
testcase_57 AC 348 ms
34,588 KB
testcase_58 AC 350 ms
34,572 KB
testcase_59 AC 350 ms
34,736 KB
testcase_60 AC 349 ms
34,516 KB
testcase_61 AC 352 ms
34,588 KB
testcase_62 AC 349 ms
34,516 KB
testcase_63 AC 351 ms
34,560 KB
testcase_64 AC 352 ms
34,676 KB
testcase_65 AC 351 ms
34,828 KB
testcase_66 AC 351 ms
34,568 KB
testcase_67 AC 351 ms
34,672 KB
testcase_68 AC 351 ms
34,724 KB
testcase_69 AC 365 ms
34,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
mint fs[500050];
int main()
{
    int n, k;
    cin>>n>>k;
    vector<mint> s(n), sr(n);
    mint ss=0, ss2=0;
    mint mp=1;
    for(int i=0; i<n; i++){
        ll m; cin>>m;
        mp*=mint(m);
        s[i]=mint(m+1)/2;
        sr[n-1-i]=s[i];
        ss+=s[i];
        ss2+=s[i]*s[i];
    }
    fac(n);
    mint ps=0;
    for(int i=1; i<=k; i++){
        ps+=f[n-1]*invf[n-1-i];
    }
    mint ans=(ss*ss-ss2)/2*ps;
    auto sp=convolution(s, sr);
    for(int i=0; i<=n; i++){
        fs[i+1]=fs[i]+invf[i];
    }
    for(int d=0; d<n-1; d++){
        ans-=f[d]*(fs[d]-fs[max(0, d-k)])*sp[d];
    }
    ans*=mp;
    cout<<ans.val()<<endl;
    return 0;
}
0