結果

問題 No.444 旨味の相乗効果
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-20 14:37:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 479 ms / 2,500 ms
コード長 2,001 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 174,728 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 03:23:12
合計ジャッジ時間 4,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 479 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 23 ms
4,380 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 242 ms
4,380 KB
testcase_13 AC 141 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 479 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 60 ms
4,376 KB
testcase_20 AC 455 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 8 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,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) { int ret = 1; while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; }
int modinv(int a) { return modpow(a, mod - 2); }
//-----------------------------------------------------------------------------------
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
vi mul_mat_vec(vvi a, vi b)
{
    int n = b.size();
    vi ret(n, 0);
    rep(i, 0, n)
    {
        ret[i] = 0;
        rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j],b[j]));
    }
    return ret;
}

vvi mul_mat_mat(vvi a, vvi b)
{
    int n = a.size();
    vvi ret(n, vi(n, 0));
    rep(i, 0, n) rep(j, 0, n)
    {
        ret[i][j] = 0;
        rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
    }
    return ret;
}
vvi fastpow(vvi x, ll n)
{
    vvi ret(x.size(), vi(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;

    while (0 < n)
    {
        if ((n % 2) == 0)
        {
            x = mul_mat_mat(x, x);
            n >>= 1;
        }
        else
        {
            ret = mul_mat_mat(ret, x);
            --n;
        }
    }
    return ret;
}
//-----------------------------------------------------------------------------------
int N; ll C, A[80];
int main() {
    cin >> N >> C;
    rep(i, 0, N) cin >> A[i];


    vvi ma(N, vi(N, 0));
    rep(i, 0, N) rep(j, i, N) ma[j][i] = A[i];
    ma = fastpow(ma, C);

    vi ve(N);
    rep(i, 0, N) ve[i] = 1;

    ve = mul_mat_vec(ma, ve);

    int ans = ve[N - 1];
    rep(i, 0, N) ans = sub(ans, modpow(A[i], C));
    cout << ans << endl;
}
0