結果

問題 No.444 旨味の相乗効果
ユーザー mayoko_mayoko_
提出日時 2016-11-12 00:14:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,500 ms
コード長 1,791 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 88,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 02:10:58
合計ジャッジ時間 2,826 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

typedef long long number;
typedef vector<number> vec;
typedef vector<vec> matrix;

ll mod_pow(ll x, ll p, ll MOD) {
    ll a = 1;
    while (p) {
        if (p%2) a = a*x%MOD;
        x = x*x%MOD;
        p/=2;
    }
    return a;
}

const ll MOD = 1e9+7;

// O( n )
matrix iden(int n) {
    matrix A(n, vec(n));
    for (int i = 0; i < n; ++i) A[i][i] = 1;
    return A;
}
// O( n^3 )
matrix mul(const matrix &A, const matrix &B) {
    matrix C(A.size(), vec(B[0].size()));
    for (int i = 0; i < (int)C.size(); ++i)
        for (int j = 0; j < (int)C[i].size(); ++j)
            for (int k = 0; k < (int)A[i].size(); ++k) {
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= MOD;
            }
    return C;
}
// O( n^3 log e )
matrix pow(const matrix &A, ll e) {
    if (e == 0) return iden(A.size());
    if (e == 1) return A;
    if (e % 2 == 0) {
        matrix tmp = pow(A, e/2);
        return mul(tmp, tmp);
    } else {
        matrix tmp = pow(A, e-1);
        return mul(A, tmp);
    }
}

int A[111];

int main() {
	int N;
	ll C;
	cin >> N >> C;
	if (C == 1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++)
		cin >> A[i];
	matrix M(N, vec(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			M[i][j] = A[i];
		}
	}
	M = pow(M, C);
	ll ans = 0;
	for (int i = 0; i < N; i++)
		ans += M[i][0];
	for (int i = 0; i < N; i++) {
		ans -= mod_pow(A[i], C, MOD);
	}
	ans = ((ans%MOD)+MOD)%MOD;
	cout << ans << endl;
	return 0;
}
0