結果
| 問題 | No.997 Jumping Kangaroo |
| コンテスト | |
| ユーザー |
iiljj
|
| 提出日時 | 2020-02-22 03:26:13 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 10,958 bytes |
| 記録 | |
| コンパイル時間 | 7,287 ms |
| コンパイル使用メモリ | 251,652 KB |
| 最終ジャッジ日時 | 2025-01-09 01:47:14 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:308:14: error: expected unqualified-id before 'const'
308 | Mat<Num>(const ll sz)
| ^~~~~
main.cpp:308:14: error: expected ')' before 'const'
308 | Mat<Num>(const ll sz)
| ~^~~~~
| )
main.cpp:310:14: error: expected unqualified-id before 'const'
310 | Mat<Num>(const Mat<Num> &mt)
| ^~~~~
main.cpp:310:14: error: expected ')' before 'const'
310 | Mat<Num>(const Mat<Num> &mt)
| ~^~~~~
| )
main.cpp: In function 'void solve()':
main.cpp:460:18: error: no matching function for call to 'Mat<mint>::Mat(int)'
460 | Mat<mint> A(2);
| ^
main.cpp:301:7: note: candidate: 'constexpr Mat<mint>::Mat()'
301 | class Mat : public vc<vc<Num>>
| ^~~
main.cpp:301:7: note: candidate expects 0 arguments, 1 provided
main.cpp:301:7: note: candidate: 'constexpr Mat<mint>::Mat(const Mat<mint>&)'
main.cpp:301:7: note: no known conversion for argument 1 from 'int' to 'const Mat<mint>&'
main.cpp:301:7: note: candidate: 'constexpr Mat<mint>::Mat(Mat<mint>&&)'
main.cpp:301:7: note: no known conversion for argument 1 from 'int' to 'Mat<mint>&&'
main.cpp: In instantiation of 'Mat<Num> Mat<Num>::pow(ll) const [with Num = mint; ll = long long int]':
main.cpp:462:14: required from here
main.cpp:374:18: error: no matching function for call to 'Mat<mint>::Mat(const ll&)'
374 | Mat<Num> ret(this->sz);
| ^~~
main.cpp:301:7: note: candidate: 'constexpr Mat<mint>::Mat()'
301 | class Mat : public vc<vc<Num>>
| ^~~
main.cpp:301:7: note: candidate expects 0 arguments, 1 provided
main.cpp:301:7: note: candidate: 'constexpr Mat<mint>::Mat(const Mat<mint>&)'
main.cpp:301:7: note: no known conversion for argument 1 from 'const ll' {aka 'const long long int'} to 'const Mat<mint>&'
main.cpp:301:7: note: candidate: 'constexpr Mat<mint>::Mat(Mat<mint>&&)'
main.cpp:301:7: note:
ソースコード
/* #region Head */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
using vll = vc<ll>;
using vvll = vvc<ll>;
using vld = vc<ld>;
using vvld = vvc<ld>;
using vs = vc<string>;
using vvs = vvc<string>;
template <class T, class U>
using um = unordered_map<T, U>;
#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))
#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))
#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))
#define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))
#define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))
#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) begin(x), end(x)
#define SIZE(x) ((ll)(x).size())
#define PREM(c) \
sort(all(c)); \
for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define UNIQ(v) v.erase(unique(ALL(v)), v.end());
constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;
// vector 入力
template <typename T>
istream &operator>>(istream &is, vc<T> &vec)
{
for (T &x : vec)
is >> x;
return is;
}
// vector 出力 (for dump)
template <typename T>
ostream &operator<<(ostream &os, vc<T> &vec)
{
ll len = SIZE(vec);
os << "{";
for (int i = 0; i < len; i++)
os << vec[i] << (i == len - 1 ? "" : ", ");
os << "}";
return os;
}
// vector 出力 (inline)
template <typename T>
ostream &operator>>(ostream &os, vc<T> &vec)
{
ll len = SIZE(vec);
for (int i = 0; i < len; i++)
os << vec[i] << (i == len - 1 ? "\n" : " ");
return os;
}
// pair 入力
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &pair_var)
{
is >> pair_var.first >> pair_var.second;
return is;
}
// pair 出力
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var)
{
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// map 出力
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var)
{
os << "{";
REPI(itr, map_var)
{
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// um 出力
template <typename T, typename U>
ostream &operator<<(ostream &os, um<T, U> &map_var)
{
os << "{";
REPI(itr, map_var)
{
os << *itr;
auto itrcp = itr;
itrcp++;
if (itrcp != map_var.end())
os << ", ";
}
os << "}";
return os;
}
// set 出力
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var)
{
os << "{";
REPI(itr, set_var)
{
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// dump
#define DUMPOUT cerr
void dump_func()
{
DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail)
{
DUMPOUT << head;
if (sizeof...(Tail) > 0)
{
DUMPOUT << ", ";
}
dump_func(move(tail)...);
}
// chmax (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
if (comp(xmax, x))
{
xmax = x;
return true;
}
return false;
}
// chmin (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
if (comp(x, xmin))
{
xmin = x;
return true;
}
return false;
}
// ローカル用
#define DEBUG_
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
<< endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
struct AtCoderInitialize
{
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
AtCoderInitialize()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} ATCODER_INITIALIZE;
/* #endregion */
struct mint
{
ll x;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint &operator+=(const mint a)
{
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a)
{
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a)
{
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const
{
mint res(*this);
return res += a;
}
mint operator-(const mint a) const
{
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const
{
mint res(*this);
return res *= a;
}
// O(log(t))
mint pow(ll t) const
{
if (!t)
return 1;
mint a = pow(t >> 1); // ⌊t/2⌋ 乗
a *= a; // ⌊t/2⌋*2 乗
if (t & 1) // ⌊t/2⌋*2 == t-1 のとき
a *= *this; // ⌊t/2⌋*2+1 乗 => t 乗
return a;
}
// for prime mod
mint inv() const
{
return pow(MOD - 2); // オイラーの定理から, x^(-1) ≡ x^(p-2)
}
mint &operator/=(const mint a)
{
return (*this) *= a.inv();
}
mint operator/(const mint a) const
{
mint res(*this);
return res /= a;
}
bool operator==(const mint a) const
{
return this->x == a.x;
}
bool operator==(const ll a) const
{
return this->x == a;
}
// mint 入力
friend istream &operator>>(istream &is, mint &x)
{
is >> x.x;
return is;
}
// mint 出力
friend ostream &operator<<(ostream &os, mint x)
{
os << x.x;
return os;
}
};
template <class Num>
class Mat : public vc<vc<Num>>
{
// using vc<vc<Num>>::vector;
ll sz;
public:
// コンストラクタ
Mat<Num>(const ll sz)
: vc<vc<Num>>(sz, vc<Num>(sz, 0)), sz(sz) {}
Mat<Num>(const Mat<Num> &mt)
: vc<vc<Num>>(mt), sz(SIZE(mt)) {}
// 行列に別の行列を足す
Mat &operator+=(const Mat &another)
{
REP(i, 0, this->sz)
REP(j, 0, this->sz)
{
(*this)[i][j] += another[i][j];
}
return *this;
}
// 行列から別の行列を引く
Mat &operator-=(const Mat &another)
{
REP(i, 0, this->sz)
REP(j, 0, this->sz)
{
(*this)[i][j] -= another[i][j];
}
return *this;
}
// 行列に別の行列を右から掛ける
Mat &operator*=(const Mat &another)
{
Mat<Num> ret(this->sz);
REP(i, 0, this->sz)
REP(j, 0, this->sz)
REP(k, 0, this->sz)
{
ret[i][j] += (*this)[i][k] * another[k][j];
}
*this = ret;
return *this;
}
// 行列に別の行列を足す
Mat operator+(const Mat &another) const
{
Mat<Num> ret(*this);
return ret += another;
}
// 行列から別の行列を引く
Mat operator-(const Mat &another) const
{
Mat<Num> ret(*this);
return ret -= another;
}
// 行列に別の行列を右から掛ける
Mat operator*(const Mat &another) const
{
Mat<Num> ret(*this);
return ret *= another;
}
// 行列の n 乗を計算する
Mat pow(ll n) const
{
// ll sz = SIZE(*this);
Mat<Num> ret(this->sz);
Mat<Num> a(*this);
REP(i, 0, sz)
{
ret[i][i] = 1;
}
while (n)
{
if (n & 1)
ret = a * ret;
a = a * a;
n >>= 1;
}
return ret;
}
template <class... T>
Mat assign(T... nums)
{
vector<Num> num_list = vector<Num>{nums...};
assert(SIZE(num_list) == sz * sz);
REP(i, 0, sz)
REP(j, 0, sz)
{
(*this)[i][j] = num_list[sz * i + j];
}
return *this;
}
};
/**
Problem
*/
void solve()
{
ll n, w, k;
cin >> n >> w >> k;
vll a(n);
cin >> a;
sort(ALL(a));
// 白い岩への着地は1回おき or 2回おきのどちらか
mint cnt1 = 0;
{
vc<vc<mint>> dp(2, vc<mint>(w + 1, 0)); // 1回おきの場合: 足して w になる組み合わせ数を数える
// dp[(i+1)%2][j] := i 回の移動で距離の総和を j とする場合の数
dp[0][0] = 1;
// 配るDP
REP(i, 0, (w + a[0] - 1) / a[0]) // 1 段階前までの移動回数
{
fill(ALL(dp[(i + 1) % 2]), 0);
for (ll ai : a) // 飛び方の種類
{
REPM(j, 0, w) // 1 段階前の総和
{
if (j + ai > w)
break;
dp[(i + 1) % 2][j + ai] += dp[i % 2][j];
}
}
cnt1 += dp[(i + 1) % 2][w];
}
}
mint cnt2 = 0;
{
vc<vc<mint>> dp(2, vc<mint>(2 * w + 1, 0)); // 1回おきの場合: 足して 2w になる組み合わせ数を数える
dp[0][0] = 1;
// dp[(i+1)%2][j] := i 回の移動で距離の総和を j とする場合の数
// 配るDP
REP(i, 0, (2 * w + a[0] - 1) / a[0]) // 1 段階前までの移動回数
{
fill(ALL(dp[(i + 1) % 2]), 0);
for (ll ai : a) // 飛び方の種類
REPM(j, 0, 2 * w) // 1 段階前の総和
{
if (j + ai > 2 * w)
break;
if (j + ai == w)
continue;
dp[(i + 1) % 2][j + ai] += dp[i % 2][j];
}
cnt2 += dp[(i + 1) % 2][2 * w];
}
}
Mat<mint> A(2);
A.assign(cnt1, cnt2, 1, 0);
A = A.pow(k);
mint n0 = 1, n1 = cnt1;
cout << (A[1][0] * n1 + A[1][1] * n0) << endl;
}
/**
* エントリポイント.
* @return 0.
*/
int main()
{
solve();
return 0;
}
iiljj