結果

問題 No.997 Jumping Kangaroo
ユーザー FF256grhyFF256grhy
提出日時 2020-02-21 23:12:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,271 ms / 2,000 ms
コード長 6,453 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 177,612 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 09:14:56
合計ジャッジ時間 20,037 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
6,816 KB
testcase_01 AC 90 ms
6,940 KB
testcase_02 AC 661 ms
6,940 KB
testcase_03 AC 261 ms
6,940 KB
testcase_04 AC 221 ms
6,940 KB
testcase_05 AC 240 ms
6,944 KB
testcase_06 AC 233 ms
6,940 KB
testcase_07 AC 215 ms
6,944 KB
testcase_08 AC 234 ms
6,944 KB
testcase_09 AC 235 ms
6,944 KB
testcase_10 AC 204 ms
6,944 KB
testcase_11 AC 236 ms
6,944 KB
testcase_12 AC 230 ms
6,940 KB
testcase_13 AC 1,012 ms
6,940 KB
testcase_14 AC 1,135 ms
6,940 KB
testcase_15 AC 999 ms
6,944 KB
testcase_16 AC 1,271 ms
6,944 KB
testcase_17 AC 972 ms
6,940 KB
testcase_18 AC 1,135 ms
6,940 KB
testcase_19 AC 1,033 ms
6,940 KB
testcase_20 AC 1,153 ms
6,944 KB
testcase_21 AC 1,052 ms
6,944 KB
testcase_22 AC 1,145 ms
6,940 KB
testcase_23 AC 1,095 ms
6,940 KB
testcase_24 AC 927 ms
6,944 KB
testcase_25 AC 956 ms
6,940 KB
testcase_26 AC 90 ms
6,940 KB
testcase_27 AC 92 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T, int N> struct Matrix {
	vector<vector<T>> v;
	Matrix(T t) {
		init();
		inc(i, N) { v[i][i] = t; }
	}
	Matrix(vector<vector<T>> const & w = { }) { init(w); }
	void init(vector<vector<T>> const & w = { }) {
		v = vector<vector<T>>(N, vector<T>(N, 0));
		assert(w.size() <= N);
		inc(i, w.size()) { assert(w[i].size() <= N);
		inc(j, w[i].size()) {
			v[i][j] = w[i][j];
		}
		}
	}
	vector<T> const & operator[](int i) const { return v[i]; }
	vector<T>       & operator[](int i)       { return v[i]; }
	friend Matrix operator+(Matrix const & a, Matrix const & b) {
		Matrix c;
		inc(i, N) {
		inc(j, N) {
			c[i][j] = a[i][j] + b[i][j];
		}
		}
		return c;
	}
	friend Matrix operator-(Matrix const & a, Matrix const & b) {
		Matrix c;
		inc(i, N) {
		inc(j, N) {
			c[i][j] = a[i][j] - b[i][j];
		}
		}
		return c;
	}
	friend Matrix operator*(Matrix const & a, Matrix const & b) {
		Matrix c;
		inc(i, N) {
		inc(j, N) {
		inc(k, N) {
			c[i][j] += a[i][k] * b[k][j];
		}
		}
		}
		return c;
	}
	friend Matrix operator^(Matrix const & a, LL b) {
		Matrix c(1), e = a; assert(b >= 0);
		while(b) { if(b & 1) { c *= e; } e *= e; b >>= 1; }
		return c;
	}
	friend Matrix & operator+=(Matrix & a, Matrix const & b) { return (a = a + b); }
	friend Matrix & operator-=(Matrix & a, Matrix const & b) { return (a = a - b); }
	friend Matrix & operator*=(Matrix & a, Matrix const & b) { return (a = a * b); }
	friend Matrix & operator^=(Matrix & a, LL             b) { return (a = a ^ b); }
	friend ostream & operator<<(ostream & os, Matrix const & m) {
		inc(i, N) {
		inc(j, N) {
			os << m[i][j] << " ";
		} os << endl;
		} return os;
	}
};

// ----

template<LL M> class ModInt {
private:
	LL v;
	pair<LL, LL> ext_gcd(LL a, LL b) {
		if(b == 0) { assert(a == 1); return { 1, 0 }; }
		auto p = ext_gcd(b, a % b);
		return { p.SE, p.FI - (a / b) * p.SE };
	}
public:
	ModInt(LL vv = 0) { v = vv; if(abs(v) >= M) { v %= M; } if(v < 0) { v += M; } }
	LL get_v() { return v; }
	ModInt inv() { return ext_gcd(M, v).SE; }
	ModInt exp(LL b) {
		ModInt p = 1, a = v; if(b < 0) { a = a.inv(); b = -b; }
		while(b) { if(b & 1) { p *= a; } a *= a; b >>= 1; }
		return p;
	}
	friend bool      operator< (ModInt    a, ModInt   b) { return (a.v <  b.v); }
	friend bool      operator> (ModInt    a, ModInt   b) { return (a.v >  b.v); }
	friend bool      operator<=(ModInt    a, ModInt   b) { return (a.v <= b.v); }
	friend bool      operator>=(ModInt    a, ModInt   b) { return (a.v >= b.v); }
	friend bool      operator==(ModInt    a, ModInt   b) { return (a.v == b.v); }
	friend bool      operator!=(ModInt    a, ModInt   b) { return (a.v != b.v); }
	friend ModInt    operator+ (ModInt    a            ) { return ModInt(+a.v); }
	friend ModInt    operator- (ModInt    a            ) { return ModInt(-a.v); }
	friend ModInt    operator+ (ModInt    a, ModInt   b) { return ModInt(a.v + b.v); }
	friend ModInt    operator- (ModInt    a, ModInt   b) { return ModInt(a.v - b.v); }
	friend ModInt    operator* (ModInt    a, ModInt   b) { return ModInt(a.v * b.v); }
	friend ModInt    operator/ (ModInt    a, ModInt   b) { return a * b.inv(); }
	friend ModInt    operator^ (ModInt    a, LL       b) { return a.exp(b); }
	friend ModInt  & operator+=(ModInt  & a, ModInt   b) { return (a = a + b); }
	friend ModInt  & operator-=(ModInt  & a, ModInt   b) { return (a = a - b); }
	friend ModInt  & operator*=(ModInt  & a, ModInt   b) { return (a = a * b); }
	friend ModInt  & operator/=(ModInt  & a, ModInt   b) { return (a = a / b); }
	friend ModInt  & operator^=(ModInt  & a, LL       b) { return (a = a ^ b); }
	friend istream & operator>>(istream & s, ModInt & b) { s >> b.v; b = ModInt(b.v); return s; }
	friend ostream & operator<<(ostream & s, ModInt   b) { return (s << b.v); }
};

// ----

using MI = ModInt< 1'000'000'007 >;

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

#define inCD(v, l, r) ((l) <  (v) && (v) <  (r))

int main() {
	IN(LL, n, w, k);
	vector<int> a(n);
	cin >> a;
	sort(ALL(a));
	
	auto id = [&](int f, int p) {
		assert(inII(f, 0, 1));
		assert(inII(p, 0, 2 * w));
		return (2 * w + 1) * f + p;
	};
	
	const int M = 40;
	Matrix<MI, 2 * (2 * M + 1)> A, v;
	inc(f, 2) {
	inc(p, w) {
		RF(e, a) {
			if(p + e <= (1 - f) * w + w) {
				int x = p + e + (f * w);
				int ff = (inCD(x, w, 2 * w) ? 1 : 0);
				A[id(f, p)][id(ff, p + e)] = 1;
			}
		}
	}
	}
	inc(f, 2) {
	incII(p, w, 2 * w) {
		A[id(f, p)][id(f, p)] = 1;
	}
	}
	
	A ^= w;
	inc(f, 2) {
	inc(g, 2) {
	incII(i, 0, 2 * w) {
	incII(j, w, 2 * w) {
		A[id(f, i)][id(g, j - w)] = exchange(A[id(f, i)][id(g, j)], 0);
	}
	}
	}
	}
	
	v[0][id(0, 0)] = 1;
	A ^= k;
	v *= A;
	OUT(v[0][id(0, 0)]);
}
0