結果

問題 No.997 Jumping Kangaroo
ユーザー pekempeypekempey
提出日時 2020-02-21 21:48:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,158 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 170,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-30 05:46:19
合計ジャッジ時間 2,932 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

// f(k) = (ちょうどW) * f(k-1) + (W を通らずちょうど 2W) * f(k-2)
// x^2 - 

pair<mint, mint> pmul(pair<mint, mint> a, pair<mint, mint> b, pair<mint, mint> c) {
  mint x = a.first * b.first;
  mint y = a.first * b.second + a.second * b.first;
  mint z = a.second * b.second;
  x += c.first * z;
  y += c.second * z;
  return make_pair(x, y);
}

pair<mint, mint> ppow(pair<mint, mint> a, ll b, pair<mint, mint> c) {
  pair<mint, mint> res(1, 0);
  while (b > 0) {
    if (b % 2 == 1) {
      res = pmul(res, a, c);
    }
    a = pmul(a, a, c);
    b /= 2;
  }
  return res;
}

int main() {
  int N, W;
  ll K;
  cin >> N >> W >> K;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  vector<mint> dp(2 * W + 1);
  dp[0] = 1;
  for (int i = 0; i < 2*W; i++) {
    if (i == W) continue;
    rep(j, N) {
      if (i + A[j] <= 2 * W) {
        dp[i + A[j]] += dp[i];
      }
    }
  }
  auto ans = ppow(make_pair(0, 1), K, make_pair(dp[2*W], dp[W]));
  cout << ans.first * dp[0] + ans.second * dp[W] << endl;
}
0