結果

問題 No.444 旨味の相乗効果
ユーザー tossytossy
提出日時 2016-11-12 01:26:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,500 ms
コード長 1,842 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 91,356 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 02:12:55
合計ジャッジ時間 2,114 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600
#define MOD 1000000007

#define MAT_N 80
long mat[MAT_N][MAT_N];

// a * b = dst O(N^3) aのほうが疎な行列だとbetter
long tmp[MAT_N][MAT_N];
void mat_mul(long a[][MAT_N], long b[][MAT_N], long dst[][MAT_N]){
  fill(tmp[0], tmp[MAT_N], 0);
  rep(i,MAT_N) rep(k,MAT_N) if(a[i][k]!=0) rep(j,MAT_N){
    tmp[i][j] += a[i][k] * b[k][j] % MOD;
  }
  rep(i,MAT_N) rep(j,MAT_N) dst[i][j] = tmp[i][j] % MOD;
}

// a^n = dst O(M^3 log N)
long tmp_pow[MAT_N][MAT_N];
void mat_pow(long a[][MAT_N], long n, long dst[][MAT_N]){
  rep(i,MAT_N) rep(j,MAT_N) tmp_pow[i][j] = a[i][j];
  fill(dst[0], dst[MAT_N], 0);
  rep(i,MAT_N) dst[i][i]=1;
  while(n>0){
    if(n&1) mat_mul(tmp_pow, dst, dst);
    mat_mul(tmp_pow, tmp_pow, tmp_pow);
    n /= 2;
  }
}

// x^n mod
long mod_pow(long x, long n, long mod){
  long res=1;
  x %= mod;
  while(n>0){
    if(n&1) res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}


int main(){
  int n; long c;
  cin>>n>>c;
  vector<long> vec(n);
  rep(i,n) scanf("%ld", &vec[i]);

  fill(mat[0], mat[n], 0);
  rep(i,n) rep(j,i+1) mat[i][j]=vec[i];

  mat_pow(mat, c-1, mat);

  long res=0;
  rep(i,n){
    rep(j,n) res += mat[i][j]*vec[j] % MOD;
    res -= mod_pow(vec[i], c, MOD);
  }
  while(res<0) res+=MOD;

  cout << res%MOD <<endl;

  return 0;
}
0