結果
| 問題 |
No.444 旨味の相乗効果
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-12 17:57:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 2,500 ms |
| コード長 | 1,195 bytes |
| コンパイル時間 | 805 ms |
| コンパイル使用メモリ | 67,804 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-24 20:58:10 |
| 合計ジャッジ時間 | 1,902 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 |
ソースコード
#include <iostream>
#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<ll> VL;
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] - powmod(a[i], oldc) + mod) % mod;
}
cout << res << endl;
}