結果

問題 No.997 Jumping Kangaroo
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-02-22 13:47:50
言語 C++17(1z)
(gcc 10.2.0 + boost 1.73.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 5,227 Byte
コンパイル時間 3,471 ms
使用メモリ 7,028 KB
最終ジャッジ日時 2021-03-08 06:30:48
合計ジャッジ時間 5,056 ms
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,424 KB
testcase_01 AC 1 ms
3,472 KB
testcase_02 AC 2 ms
3,312 KB
testcase_03 AC 2 ms
3,476 KB
testcase_04 AC 1 ms
3,404 KB
testcase_05 AC 2 ms
3,440 KB
testcase_06 AC 2 ms
3,408 KB
testcase_07 AC 2 ms
3,348 KB
testcase_08 AC 2 ms
3,296 KB
testcase_09 AC 2 ms
3,388 KB
testcase_10 AC 1 ms
3,336 KB
testcase_11 AC 2 ms
3,396 KB
testcase_12 AC 1 ms
3,320 KB
testcase_13 AC 2 ms
3,352 KB
testcase_14 AC 1 ms
3,476 KB
testcase_15 AC 1 ms
3,388 KB
testcase_16 AC 2 ms
3,380 KB
testcase_17 AC 2 ms
3,308 KB
testcase_18 AC 2 ms
3,336 KB
testcase_19 AC 2 ms
3,440 KB
testcase_20 AC 2 ms
3,476 KB
testcase_21 AC 2 ms
3,440 KB
testcase_22 AC 1 ms
3,324 KB
testcase_23 AC 2 ms
3,328 KB
testcase_24 AC 2 ms
3,308 KB
testcase_25 AC 2 ms
3,392 KB
testcase_26 AC 2 ms
3,404 KB
testcase_27 AC 2 ms
3,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
    int ret = 1; while (b > 0) {
        if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
    } return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
typedef vector<int> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
    return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
    return ret;
}
Mat fastpow(Mat x, ll n)
{
    Mat ret(x.size(), Vec(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;
    while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
    return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }


// example: n=2
// x[0] = init[0], x[1] = init[1]
// x[i] = co[0] * x[i-1] + co[1] * x[i-2]
int solveLinearRecurrenceFormula(vector<int> init, vector<int> coefficient, ll idx) {
    int n = init.size();

    Vec v = init;
    Mat m(n, Vec(n, 0));
    rep(i, 0, n - 1) m[i][i + 1] = 1;
    rep(i, 0, n) m[n - 1][i] = coefficient[n - 1 - i];

    m = fastpow(m, idx);
    v = mulMatVec(m, v);

    return v[0];
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/











int N, W, A[101]; ll K;
mint dp[201];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> W >> K;
	rep(i, 0, N) cin >> A[i];

    dp[0] = 1;
    rep(cu, 0, W * 2) rep(i, 0, N) dp[cu + A[i]] += dp[cu];
    dp[2 * W] -= dp[W] * dp[W];

    int ans = solveLinearRecurrenceFormula({ dp[0].get(), dp[W].get() }, { dp[W].get(), dp[2 * W].get() }, K);
    cout << ans << endl;
}





0