結果

問題 No.936 Are
ユーザー FF256grhyFF256grhy
提出日時 2019-12-01 09:28:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 548 ms / 3,000 ms
コード長 5,702 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 179,524 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 10:26:31
合計ジャッジ時間 7,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 25 ms
4,376 KB
testcase_02 AC 548 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 146 ms
4,380 KB
testcase_14 AC 440 ms
4,380 KB
testcase_15 AC 172 ms
4,376 KB
testcase_16 AC 314 ms
4,380 KB
testcase_17 AC 284 ms
4,380 KB
testcase_18 AC 113 ms
4,376 KB
testcase_19 AC 514 ms
4,380 KB
testcase_20 AC 524 ms
4,376 KB
testcase_21 AC 465 ms
4,380 KB
testcase_22 AC 282 ms
4,376 KB
testcase_23 AC 534 ms
4,380 KB
testcase_24 AC 531 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, 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  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

template<LL M> class ModInt {
private:
	LL v;
public:
	ModInt(LL vv = 0) { v = vv; if(abs(v) >= M) { v %= M; } if(v < 0) { v += M; } }
	LL get_v() { return v; }
	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;
	}
	ModInt inv() { return ext_gcd(M, v).SE; }
	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 };
	}
	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, LL       b) { return a.exp(b); }
	friend ModInt    operator/ (ModInt    a, ModInt   b) { return a * b.inv(); }
	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 ModInt  & operator/=(ModInt  & a, ModInt   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 >;

enum Type {
	LOSE,
	WIN,
	MATE,
	ELSE
};

int main() {
	using A = array<int, 5>;
	const int S = 2 * 5 * 5 * 5 * 5;
	
	auto id = [&](A a) {
		int v = 0;
		inc(i, 5) { v = 5 * v + a[i]; }
		return v;
	};
	
	vector<Type> type(S, ELSE);
	vector<vector<int>> g(S);
	inc(n, 2) {
	inc(L, 5) {
	inc(R, 5) {
	inc(l, 5) {
	inc(r, 5) {
		int v = id({ n, L, R, l, r });
		if(L + R == 0) { type[v] = LOSE; continue; }
		
		if(L != 0 && l != 0) { g[v].PB(id({ 1 - n, (l + L) % 5, r, L, R })); }
		if(R != 0 && l != 0) { g[v].PB(id({ 1 - n, (l + R) % 5, r, L, R })); }
		if(L != 0 && r != 0) { g[v].PB(id({ 1 - n, l, (r + L) % 5, L, R })); }
		if(R != 0 && r != 0) { g[v].PB(id({ 1 - n, l, (r + R) % 5, L, R })); }
		
		inc(ll, 5) {
		inc(rr, 5) {
			if(
				(ll + rr != 0) &&
				(L + R == ll + rr || L + R - 5 == ll + rr) &&
				MP(ll, rr) != MP(L, R) &&
				MP(ll, rr) != MP(R, L)
			) { g[v].PB(id({ 1 - n, l, r, ll, rr })); }
		}
		}
	}
	}
	}
	}
	}
	
	inc(v, S) {
		RF(e, g[v]) { if(type[e] == LOSE) { type[v] = WIN; } }
	}
	
	inc(v, S) {
		int c = 0;
		RF(e, g[v]) { if(type[e] == WIN) { c++; } }
		if(c > 0 && c == SI(g[v])) { type[v] = MATE; }
	}
	
	int k;
	A a;
	inc(i, 5) {
		cin >> a[i];
		if(i == 0) { cin >> k; }
	}
	if(a[0] == 1) {
		swap(a[1], a[3]);
		swap(a[2], a[4]);
	}
	
	vector<MI> dp(S, 0);
	dp[id(a)] = 1;
	MI ans = 0;
	inc(i, k) {
		vector<MI> dp2(S, 0);
		inc(v, S) {
			if(dp[v] == 0) { continue; }
			int n = v / (S / 2);
			RF(e, g[v]) {
				if(n == 1 && (
					(type[v] == WIN  && type[e] != LOSE) ||
					(type[v] == ELSE && type[e] == WIN )
				) ) { continue; }
				dp2[e] += dp[v];
				if(n == 0 && type[e] == LOSE) { ans += dp[v]; }
			}
		}
		dp = dp2;
	}
	
	cout << ans << endl;
	
	return 0;
}
0