結果

問題 No.997 Jumping Kangaroo
ユーザー tnakao0123tnakao0123
提出日時 2020-02-23 01:36:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,247 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 98,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 08:07:58
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_07 AC 1 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 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 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 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 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 #

/* -*- coding: utf-8 -*-
 *
 * 997.cc:  No.997 Jumping Kangaroo - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 40;
const int MAX_W2 = MAX_W * 2;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;
typedef int mat[2][2];

/* global variables */

int as[MAX_W2];
int dp[MAX_W2 + 1];
mat ma, mb;

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

int do_dp(int n, int w) {
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;

  for (int i = 0; i < w; i++)
    if (dp[i] > 0)
      for (int j = 0; j < n && i + as[j] <= w; j++)
	addmod(dp[i + as[j]], dp[i]);

  return dp[w];
}

inline void initmat(mat a) { memset(a, 0, sizeof(mat)); }
inline void unitmat(mat a) { initmat(a); a[0][0] = a[1][1] = 1; }
inline void copymat(const mat a, mat b) { memcpy(b, a, sizeof(mat)); }

inline void mulmat(const mat a, const mat b, mat c) {
  c[0][0] = ((ll)a[0][0] * b[0][0] % MOD + (ll)a[0][1] * b[1][0] % MOD) % MOD;
  c[0][1] = ((ll)a[0][0] * b[0][1] % MOD + (ll)a[0][1] * b[1][1] % MOD) % MOD;
  c[1][0] = ((ll)a[1][0] * b[0][0] % MOD + (ll)a[1][1] * b[1][0] % MOD) % MOD;
  c[1][1] = ((ll)a[1][0] * b[0][1] % MOD + (ll)a[1][1] * b[1][1] % MOD) % MOD;
}

inline void powmat(const mat a, ll b, mat c) {
  mat s, t;
  copymat(a, s);
  unitmat(c);

  while (b > 0) {
    if (b & 1) {
      mulmat(c, s, t);
      copymat(t, c);
    }

    mulmat(s, s, t);
    copymat(t, s);
    b >>= 1;
  }
}

/* main */

int main() {
  int n, w;
  ll k;
  scanf("%d%d%lld", &n, &w, &k);
  int w2 = w * 2;

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);

  int d1 = do_dp(n, w);
  int d2 = (do_dp(n, w2) + (MOD - (ll)d1 * d1 % MOD)) % MOD;
  //printf("%d %d\n", d1, d2);

  // f_n = d1 * f_{n-1} + d2 * f_{n-2}
  ma[0][0] = 0;  ma[0][1] = 1;
  ma[1][0] = d2; ma[1][1] = d1;
  powmat(ma, k, mb);

  int r = (mb[0][0] + (ll)mb[0][1] * d1 % MOD) % MOD;
  printf("%d\n", r);
  return 0;
}
0