結果

問題 No.444 旨味の相乗効果
ユーザー ytftytft
提出日時 2021-03-30 10:48:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 175,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 07:16:20
合計ジャッジ時間 5,113 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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(int 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 p(long long a,long long n){
    long long ans=1;
    long long temp=a;
    while(n>0){
        if(n%2){
            ans=(ans*temp)%MOD;
        }
        temp=(temp*temp)%MOD;
        n=n/2;
    }
    return ans;
}

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