結果
問題 | No.936 Are |
ユーザー | FF256grhy |
提出日時 | 2019-12-01 09:28:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 570 ms / 3,000 ms |
コード長 | 5,702 bytes |
コンパイル時間 | 1,830 ms |
コンパイル使用メモリ | 181,776 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-21 04:21:16 |
合計ジャッジ時間 | 7,792 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 25 ms
6,820 KB |
testcase_02 | AC | 570 ms
6,820 KB |
testcase_03 | AC | 3 ms
6,816 KB |
testcase_04 | AC | 5 ms
6,816 KB |
testcase_05 | AC | 3 ms
6,820 KB |
testcase_06 | AC | 4 ms
6,820 KB |
testcase_07 | AC | 3 ms
6,816 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 4 ms
6,816 KB |
testcase_10 | AC | 3 ms
6,816 KB |
testcase_11 | AC | 4 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,816 KB |
testcase_13 | AC | 152 ms
6,820 KB |
testcase_14 | AC | 457 ms
6,816 KB |
testcase_15 | AC | 180 ms
6,820 KB |
testcase_16 | AC | 329 ms
6,816 KB |
testcase_17 | AC | 293 ms
6,816 KB |
testcase_18 | AC | 118 ms
6,816 KB |
testcase_19 | AC | 533 ms
6,820 KB |
testcase_20 | AC | 547 ms
6,820 KB |
testcase_21 | AC | 486 ms
6,820 KB |
testcase_22 | AC | 294 ms
6,820 KB |
testcase_23 | AC | 555 ms
6,820 KB |
testcase_24 | AC | 557 ms
6,816 KB |
ソースコード
#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; }