結果

問題 No.2396 等差二項展開
ユーザー 👑 NachiaNachia
提出日時 2023-07-28 21:59:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 6,000 ms
コード長 1,585 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 83,492 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 05:53:20
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 10 ms
6,944 KB
testcase_17 AC 31 ms
6,940 KB
testcase_18 AC 48 ms
6,940 KB
testcase_19 AC 68 ms
6,944 KB
testcase_20 AC 2 ms
6,948 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 41 ms
6,944 KB
testcase_24 AC 52 ms
6,944 KB
testcase_25 AC 52 ms
6,940 KB
testcase_26 AC 47 ms
6,944 KB
testcase_27 AC 52 ms
6,944 KB
testcase_28 AC 48 ms
6,944 KB
testcase_29 AC 52 ms
6,944 KB
testcase_30 AC 47 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

//using Modint = atcoder::static_modint<998244353>;
using Modint = atcoder::modint;

vector<Modint> conv_circ(int n, const vector<Modint>& a, const vector<Modint>& b){
    vector<Modint> tmp(n*2);
    rep(i,n) rep(j,n) tmp[i+j] += a[i] * b[i];
    rep(i,n) tmp[i] += tmp[i+n];
    return tmp;
}

vector<Modint> sq_circ(int n, const vector<Modint>& a, Modint m){
    vector<Modint> tmp(n*2);
    rep(i,n) rep(j,i) tmp[i+j] += a[i] * a[j];
    rep(i,n*2) tmp[i] += tmp[i];
    rep(i,n) tmp[i*2] += a[i] * a[i];
    rep(i,n) tmp[i] += tmp[i+n] * m;
    return tmp;
}

void add_circ(int n, vector<Modint>& b, Modint m){
    Modint tmp = b[n-1];
    for(int i=n-1; i>=1; i--) b[i] += b[i-1];
    b[0] += tmp * m;
}

vector<Modint> pow_circ(int n, i64 N, Modint m){
    if(N == 0){
        vector<Modint> ans(n);
        ans[0] = 1;
        return ans;
    }
    auto tmp = sq_circ(n, pow_circ(n, N/2, m), m);
    if(N%2 == 1) add_circ(n, tmp, m);
    return tmp;
}

int main(){
    i64 N, M, L, K, B; cin >> N >> M >> L >> K >> B;
    Modint::set_mod(B);
    auto X = pow_circ(L, N, M);
    cout << X[K].val() << endl;
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0