結果

問題 No.137 貯金箱の焦り
コンテスト
ユーザー addx
提出日時 2026-03-31 22:53:15
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 2,767 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,767 ms
コンパイル使用メモリ 379,816 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2026-03-31 22:54:16
合計ジャッジ時間 12,214 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 TLE * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = unsigned __int128_t;
using mint = atcoder::static_modint<1234567891>;
const int mod = 1234567891;
#include <chrono>
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
template<class T>
bool chmin(T& a, const T& b){
    if (b < a){
        a = b;
        return true;
    }
    else { 
        return false;
    }
}
template<class T> 
bool chmax(T& a, const T& b){
    if (a < b){
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template<typename T> 
vector<T> conv(vector<T> a, vector<T> b){
    vector<T> vec((int)a.size() + (int)b.size());
    for (int i = 0; i < (int)a.size(); i++){
        for (int j = 0; j < (int)b.size(); j++){
            vec[i + j] += a[i] * b[j];
        }
    }
    return vec;
}
//P(x) / Q(x)のn項の係数を求める
template<typename T>
T Bostan_Mori(ll n, vector<T> x, vector<T> y){
    while(n){
        vector<T> yy = y;
        for (int i = 1; i < (int)y.size(); i += 2){
            yy[i] = -y[i];
        }
        vector<T> xx = conv(x, yy);
        yy = conv(y, yy); 
        for (int i = 0; i < (int)y.size(); i++){
            y[i] = yy[i * 2];
        }
        vector<T> z(((int)xx.size() + 1 - (n & 1)) / 2);
        if (n & 1){
            for (int i = 1; i < (int)xx.size(); i += 2){
                z[i / 2] = xx[i];
            }
        }
        else {
            for (int i = 0; i < (int)xx.size(); i += 2){
                z[i / 2] = xx[i];
            }
        }
        x = z;
        n >>= 1;
    }
    return x[0] / y[0];
}
// ak = x0 * ak - 1 + ... + xk - 1 * a0となるk項間漸化式のn項目を求める 
template<typename T>
T Linear_Recurrence(ll n, vector<T> x, vector<T> a){
    int k = (int)x.size();
    if (n < (int)a.size()){
        return a[n];
    }
    vector<T> q(k + 1);
    q[0] = T(1);
    for (int i = 0; i < k; i++){
        q[i + 1] = -x[i];
    }
    auto p = atcoder::convolution(q, a);
    p.resize(k);
    return Bostan_Mori<T>(n, p, q);
}
void solve(){
    ll n, m;
    cin >> n >> m;
    vector<mint> x = {1};
    for (int i = 0; i < n; i++){
        ll a;
        cin >> a;
        vector<mint> t(a + 1);
        t[0] = 1;
        t[a] = -1;
        x = conv(x, t);
    }
    vector<mint> now = {1};
    cout << Bostan_Mori<mint>(m, now, x).val() << '\n';
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;   
    while(t--){
        cout << fixed << setprecision(15);          
        solve();
    }   
}
0