結果

問題 No.1886 Sum of Slide Max
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-21 03:23:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 107,704 KB
実行使用メモリ 18,832 KB
最終ジャッジ日時 2023-08-23 11:41:39
合計ジャッジ時間 4,883 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
18,464 KB
testcase_01 AC 18 ms
18,576 KB
testcase_02 AC 18 ms
18,756 KB
testcase_03 AC 17 ms
18,700 KB
testcase_04 AC 17 ms
18,736 KB
testcase_05 AC 287 ms
18,596 KB
testcase_06 AC 31 ms
18,528 KB
testcase_07 AC 227 ms
18,624 KB
testcase_08 AC 308 ms
18,448 KB
testcase_09 AC 305 ms
18,556 KB
testcase_10 AC 314 ms
18,832 KB
testcase_11 AC 303 ms
18,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

using ll = long long;
const long long modc=998244353, MAX=1000000;
vector<long long> f, finv;

long long inv(long long x){
    long long ans = 1, e = modc-2;
    x %= modc;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * x) % modc;
        e = e >> 1LL;
        x = (x*x) % modc;
    }

    return ans;
}

void init(){
    f.resize(MAX+1); finv.resize(MAX+1);
    f[0] = 1;
    for (int i=1; i<=MAX; i++) f[i] = (f[i-1]*i) % modc;
    finv[MAX] = inv(f[MAX]);
    for (int i=MAX-1; i>=0; i--) finv[i] = (finv[i+1] * (i+1)) % modc;
}

long long P(long long n, long long k){
    if (n < k || k < 0) return 0;

    return (f[n] * finv[n-k]) % modc;
}

int main(){

    init();
    ll N, ans;
    cin >> N;
    for (ll K=1; K<=N; K++){
        ans = ((N-K+1) * K) % modc;
        ans = ans * P(N+1, N+1) % modc;
        ans = ans * inv(K+1) % modc;
        cout << ans << endl;
    }

    return 0;
}
0