結果

問題 No.444 旨味の相乗効果
ユーザー koba-e964koba-e964
提出日時 2016-11-12 17:45:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 87 ms / 2,500 ms
コード長 1,648 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 96,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 02:17:02
合計ジャッジ時間 2,650 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

vector<VL> mul(const vector<VL> &A, const vector<VL> &B) {
  int n = A.size();
  int m = B.size();
  int l = B[0].size();
  vector<VL> res(n, VL(l));
  REP(i, 0, n) {
    REP(j, 0, m) {
      REP(k, 0, l) {
	res[i][k] += A[i][j] * B[j][k];
	res[i][k] %= mod;
      }
    }
  }
  return res;
}

ll powmod(ll x, ll e) {
  ll sum = 1;
  ll cur = x % mod;
  while (e > 0) {
    if (e % 2) {
      sum = sum * cur % mod;
    }
    cur = cur * cur % mod;
    e /= 2;
  }
  return sum;
}

int main(void){
  int n;
  ll c;
  cin >> n >> c;
  VL a(n);
  REP(i, 0, n) {
    cin >> a[i];
  }
  vector<VL > A(n, VL(n));
  REP(i, 0, n) {
    REP(j, i, n) {
      A[i][j] = a[j];
    }
  }
  vector<VL> sum(n, VL(n)), cur;
  cur = A;
  REP(i, 0, n) {
    sum[i][i] = 1;
  }
  ll oldc = c;
  while (c > 0) {
    if (c % 2) {
      sum = mul(sum, cur);
    }
    cur = mul(cur, cur);
    c /= 2;
  }
  ll res = 0;
  REP(i, 0, n) {
    res = (res + sum[0][i]) % mod;
    res = (res - powmod(a[i], oldc) + mod) % mod;
  }
  cout << res << endl;
}
0