結果

問題 No.995 タピオカオイシクナーレ
ユーザー mamekin
提出日時 2020-02-24 10:59:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 4,216 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 126,004 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 22:49:43
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;
template <class T1>
class Operators
{
public:
template <class T2>
const T1 operator+(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
return ans += right;
}
template <class T2>
const T1 operator-(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
return ans -= right;
}
template <class T2>
const T1 operator*(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
return ans *= right;
}
template <class T2>
const T1 operator/(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
return ans /= right;
}
template <class T2>
const T1 operator%(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
return ans %= right;
}
bool operator!=(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return !(left == right);
}
bool operator>(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return right < left;
}
bool operator<=(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return !(right < left);
}
bool operator>=(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return !(left < right);
}
};
class Mod : public Operators<Mod>
{
private:
static const int MOD = 1000000007;
long long a;
public:
Mod(){
a = 0;
}
Mod(long long x){
a = (x % MOD + MOD) % MOD;
}
Mod& operator+=(const Mod& x){
a = (a + x.a) % MOD;
return *this;
}
Mod& operator-=(const Mod& x){
a = (a - x.a + MOD) % MOD;
return *this;
}
Mod& operator*=(const Mod& x){
a = (a * x.a) % MOD;
return *this;
}
Mod& operator/=(const Mod& x){ // MOD
int b = MOD - 2;
long long c = x.a;
while(b > 0){
if(b & 1){
a *= c;
a %= MOD;
}
c *= c;
c %= MOD;
b >>= 1;
}
return *this;
}
bool operator==(const Mod& x) const{
return a == x.a;
}
long long getValue(){
return a;
}
};
//
template <class T>
vector<vector<T> > matrixProduct(const vector<vector<T> >& x, const vector<vector<T> >& y)
{
int a = x.size();
int b = x[0].size();
int c = y[0].size();
vector<vector<T> > z(a, vector<T>(c, 0));
for(int i=0; i<a; ++i){
for(int j=0; j<c; ++j){
for(int k=0; k<b; ++k){
z[i][j] += x[i][k] * y[k][j];
}
}
}
return z;
}
//
template <class T>
vector<vector<T> > matrixPower(const vector<vector<T> >& x, long long k)
{
int n = x.size();
vector<vector<T> > y(n, vector<T>(n, 0));
for(int i=0; i<n; ++i)
y[i][i] = 1; //
vector<vector<T> > z = x;
while(k > 0){
if(k & 1)
y = matrixProduct(y, z);
z = matrixProduct(z, z);
k >>= 1;
}
return y;
}
int main()
{
int n, m, p, q;
long long k;
cin >> n >> m >> k >> p >> q;
vector<int> b(n);
for(int i=0; i<n; ++i)
cin >> b[i];
Mod x = Mod(p) / q;
vector<vector<Mod> > v =
{
{Mod(1) - x, x},
{x, Mod(1) - x},
};
v = matrixPower(v, k);
Mod ans = 0;
for(int i=0; i<m; ++i)
ans += v[1][1] * b[i];
for(int i=m; i<n; ++i)
ans += v[0][1] * b[i];
cout << ans.getValue() << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0