結果

問題 No.997 Jumping Kangaroo
ユーザー koi_kotyakoi_kotya
提出日時 2020-02-21 23:08:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,548 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 170,748 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 09:13:37
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

vector<vector<ll>> prod(vector<vector<ll>>& a, vector<vector<ll>>& b) {
    vector<vector<ll>> ret(a.size(),vector<ll>(b[0].size(),0));
    for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) {
        (ret[i][j] += a[i][k]*b[k][j]%mod) %= mod;
    }
    return ret;
}

int main() {
    int n,w;
    ll k;
    cin >> n >> w >> k;
    vector<ll> dp(2*w+1,0);
    vector<int> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    dp[0] = 1;
    for (int i = 0;i < 2*w;++i) {
        for (int j = 0;j < n;++j) if (i+a[j] <= 2*w) (dp[i+a[j]] += dp[i]) %= mod;
    }
    vector<vector<ll>> c(2,vector<ll>(2)),b(2,vector<ll>(1));
    c[0][1] = 1;
    c[1][1] = dp[w];
    c[1][0] = (dp[2*w]-dp[w]*dp[w]%mod+mod)%mod;
    b[0][0] = 1;
    b[1][0] = dp[w];
    while (k) {
        if (k&1) b = prod(c,b);
        c = prod(c,c);
        k >>= 1;
    }
    cout << b[0][0] << endl;
}
0