結果

問題 No.444 旨味の相乗効果
ユーザー ytftytft
提出日時 2021-03-30 12:51:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,297 ms / 2,500 ms
コード長 1,927 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 176,528 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 08:55:41
合計ジャッジ時間 8,227 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int MOD=1000000007;
template<typename type=int>
class Matrix{
public:
    vector<vector<type>> value;
    Matrix(vector<vector<type>> e){
        value=e;
    }
    Matrix<type> operator * (Matrix a){
        vector<vector<type>> ret(value.size(),vector<type>(a.value[0].size()));
        type temp;
        for(int i=value.size()-1;i>=0;i--){
            for(int j=a.value[0].size()-1;j>=0;j--){
                temp=0;
                for(int k=a.value.size()-1;k>=0;k--){
                    temp=(temp+value[i][k]*a.value[k][j])%MOD;
                }
                ret[i][j]=temp;
            }
        }
        return Matrix(ret);
    }
    Matrix<type> pow(long long p){
        Matrix temp=value;
        Matrix ans=temp;
        bool flg=false;
        while(p>0){
            if(p%2){
                if(flg){
                    ans=ans*temp;
                }else{
                    flg=true;
                    ans=temp;
                }
            }
            p=p/2;
            temp=temp*temp;
        }
        return ans;
    }
};

long long pawf(long long a,long long n){
    long long ans=1;
    long long temp=a%MOD;
    while(n>0){
        if(n%2){
            ans=(ans*temp)%MOD;
        }
        temp=(temp*temp)%MOD;
        n=n/2;
    }
    return ans;
}

int main(){
    long long n,c;
    cin>>n>>c;
    Matrix<long long> b(vector<vector<long long>>(n,vector<long long>(1,1)));
    vector<vector<long long>> Av(n,vector<long long>(n,0));
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            Av[i][j]=a[j]%MOD;
        }
    }

    Matrix<long long> A(Av);
    Matrix<long long> p=A.pow(c);
    long long ans=(A.pow(c)*b).value[n-1][0];
    for(int i=0;i<n;i++){
        ans=ans-pawf(a[i],c);
    }
    while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}
0