結果

問題 No.997 Jumping Kangaroo
ユーザー ShibuyapShibuyap
提出日時 2020-02-22 00:15:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,583 bytes
コンパイル時間 1,877 ms
コンパイル使用メモリ 173,728 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 10:44:13
合計ジャッジ時間 2,955 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 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 1 ms
5,376 KB
testcase_16 AC 1 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 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005



typedef vector<ll> vvv;
typedef vector<vector<ll>> mmm;
const ll MOD = 1000000007;

int m; // 遷移行列のサイズ
// DPの更新
vector<ll> matmul(vector<ll> &dp, vector<vector<ll>> &mt){
    vvv ret(m,0);
    rep(i,m){
        rep(j,m){
            ret[i] += mt[i][j] * dp[j] % MOD;
            ret[i] %= MOD;
        }
    }
    return ret;
}
// 遷移行列の更新
mmm update_matmul(mmm &mt){
    mmm ret(m, vvv(m,0));
    rep(i,m){
        rep(j,m){
            rep(k,m){
                ret[i][j] += mt[i][k] * mt[k][j] % MOD;
                ret[i][j] %= MOD;
            }
        }
    }
    return ret;
}

void matpow(vvv &dp, mmm &mt, ll k){
    int m = dp.size();
    while(k){
        if(k & 1) dp = matmul(dp, mt);
        mt = update_matmul(mt);
        k /= 2;
    }
}

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}

int main() {
    ll n, w, k;
    cin >> n >> w >> k;
    ll a[n];
    rep(i,n)cin >> a[i];
    sort(a,a+n);
    

    ll ans = 0;


    ll dp[200] = {};
    dp[0] = 1;

    rep(i,w*2+1){
        rep(j,n){
            dp[i + a[j]] += dp[i];
            dp[i + a[j]] %= MOD;
        }
    }

    

    ll x = dp[w];
    ll y = dp[w*2] - dp[w] * dp[w];
    ll z = dp[w*2];
    y = mod(y, MOD);

    // cout << x << ' ' << y << ' ' << z << endl;

    vvv dp2(2);
    mmm mt(2,vvv(2));
    dp2[0] = x;
    dp2[1] = 1;
    mt[0][0] = x; mt[0][1] = y;
    mt[1][0] = 1; mt[1][1] = 0;

    m = 2;
    matpow(dp2, mt, k);

    ans = dp2[1];

    cout << ans << endl;
    return 0;
}
 
 
0