結果

問題 No.444 旨味の相乗効果
ユーザー ytftytft
提出日時 2021-03-30 10:41:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,901 bytes
コンパイル時間 15,125 ms
コンパイル使用メモリ 406,872 KB
実行使用メモリ 35,964 KB
最終ジャッジ日時 2023-08-20 07:12:03
合計ジャッジ時間 20,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

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+=value[i][k]*a.value[k][j];
                }
                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;
    }
};

mp::cpp_int p(mp::cpp_int a,mp::cpp_int n){
    mp::cpp_int ans=1;
    mp::cpp_int temp=a;
    while(n>0){
        if(n%2){
            ans*=temp;
        }
        temp=temp*temp;
        n=n/2;
    }
    return ans;
}

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