結果

問題 No.997 Jumping Kangaroo
ユーザー mamekin
提出日時 2020-02-24 17:52:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 4,250 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 123,348 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 06:12:03
合計ジャッジ時間 2,440 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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, w;
long long k;
cin >> n >> w >> k;
vector<int> a(n);
for(int i=0; i<n; ++i)
cin >> a[i];
vector<Mod> dp(3*w, 0);
dp[0] = 1;
for(int i=0; i<w; ++i){
for(int j=0; j<n; ++j){
dp[i+a[j]] += dp[i];
}
}
vector<vector<Mod> > v(w+1, vector<Mod>(w+1, 0));
for(int i=0; i<=w; ++i){
v[0][i] = dp[w+i];
v[i][0] = dp[w-i];
}
v = matrixPower(v, k);
cout << v[0][0].getValue() << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0