結果

問題 No.997 Jumping Kangaroo
ユーザー batsumarubatsumaru
提出日時 2020-02-21 23:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,714 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 171,676 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 09:36:58
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll MOD = 1e9 + 7;

vector<vector<ll>> mul(vector<vector<ll>> &a, vector<vector<ll>> &b) {
  ll n = SZ(a);
  vector<vector<ll>> res(n, vector<ll>(n, 0));
  REP(i, n) REP(j, n) REP(k, n) {
    (res[i][j] += a[i][k] * b[k][j] % MOD) %= MOD;
  }
  return res;
}

vector<vector<ll>> modpow(vector<vector<ll>> &a, ll b) {
  ll n = SZ(a);
  vector<vector<ll>> ret(n, vector<ll>(n));
  if (b == 0) {
    REP(i, n) { ret[i][i] = 1; }
    return ret;
  }
  if (b % 2 == 0) {
    vector<vector<ll>> t = modpow(a, b / 2);
    ret = mul(t, t);
  } else {
    vector<vector<ll>> t = modpow(a, (b - 1) / 2);
    vector<vector<ll>> u = mul(t, t);
    ret = mul(a, u);
  }
  return ret;
}

int main() {
  ll N, W, K;
  cin >> N >> W >> K;
  vector<ll> a(N);
  REP(i, N) { cin >> a[i]; }
  vector<ll> dp(10000, 0), dp2(10000, 0);
  dp[0] = 1;
  REP(i, W) {
    REP(j, N) { (dp[i + a[j]] += dp[i]) %= MOD; }
  }
  dp2[0] = 1;
  REP(i, 2 * W) {
    REP(j, N) {
      if (i + a[j] == W || i == W) {
        continue;
      }
      (dp2[i + a[j]] += dp2[i]) %= MOD;
    }
  }
  vector<vector<ll>> A(2, vector<ll>(2));
  A[0][0] = dp[W];
  A[0][1] = dp2[2 * W];
  A[1][0] = 1;
  A[1][1] = 0;
  vector<vector<ll>> C = modpow(A, K - 1);
  ll ans = (dp[W] * C[0][0]) % MOD + C[0][1] % MOD;
  cout << ans << endl;
}
0