結果
問題 | No.31 悪のミックスジュース |
ユーザー | 沙耶花 |
提出日時 | 2021-10-21 14:35:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 66 ms / 5,000 ms |
コード長 | 2,145 bytes |
コンパイル時間 | 4,169 ms |
コンパイル使用メモリ | 272,628 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-21 08:58:05 |
合計ジャッジ時間 | 5,467 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 44 ms
4,348 KB |
testcase_02 | AC | 48 ms
4,348 KB |
testcase_03 | AC | 66 ms
4,348 KB |
testcase_04 | AC | 64 ms
4,348 KB |
testcase_05 | AC | 63 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 64 ms
4,348 KB |
testcase_08 | AC | 63 ms
4,348 KB |
testcase_09 | AC | 59 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 19 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 56 ms
4,348 KB |
testcase_15 | AC | 2 ms
4,348 KB |
testcase_16 | AC | 4 ms
4,348 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 2000000000000000000 template <class S, S (*op0)(S, S), S (*e0)(), S (*op1)(S, S), S (*e1)() > struct matrix{ vector<vector<S>> v; int _h,_w; matrix(vector<vector<S>> X){ v = X; _h = X.size(); _w = 0; if(X.size()>0)_w = X[0].size(); } matrix(int h,int w){ v.resize(h,vector<S>(w,e0())); _h = h; _w = w; } void add_element(int from,int to,S x){ v[to][from] = op0(v[to][from],x); } matrix e(){ assert(_h==_w); matrix<S,op0,e0,op1,e1> ret(_h,_w); for(int i=0;i<_h;i++){ for(int j=0;j<_w;j++){ if(i==j)ret.v[i][j] = e1(); else ret.v[i][j] = e0(); } } return ret; } matrix &operator*=(const matrix &another){ matrix<S,op0,e0,op1,e1> ret(_h,another._w); for(int i=0;i<_h;i++){ for(int j=0;j<another._w;j++){ ret.v[i][j] = e0(); for(int k=0;k<_w;k++){ ret.v[i][j] = op0(ret.v[i][j],op1(v[i][k],another.v[k][j])); } } } v = ret.v; return (*this); } matrix operator*(const matrix &another)const{ return (matrix(*this)*=another); } matrix pow(long long cnt){ matrix<S,op0,e0,op1,e1> ret = e(); auto temp = *this; while(cnt!=0LL){ if((cnt&1)==1){ ret *= temp; } temp *= temp; cnt>>=1; } return ret; } }; long long op0(long long a,long long b){ return min(a,b); } long long e0(){ return Inf; } long long op1(long long a,long long b){ return min((long long)Inf,a+b); } long long e1(){ return 0; } int main(){ long long N,V; cin>>N>>V; long long ans = 0LL; vector<long long> C(N); rep(i,N){ cin>>C[i]; ans += C[i]; V --; } if(V<0){ cout<<ans<<endl; return 0; } rep(i,N-1)C[i+1] += C[i]; matrix<long long,op0,e0,op1,e1> M(N,N); rep(i,N-1){ M.add_element(i,i+1,0); } rep(i,N){ M.add_element(i,0,C[i]); } matrix<long long,op0,e0,op1,e1> temp(N,1); temp.v[0][0] = ans; temp *= M.pow(V); cout<<temp.v[0][0]<<endl; return 0; }