結果
問題 | No.936 Are |
ユーザー | ei1333333 |
提出日時 | 2019-11-29 23:26:10 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 6,902 bytes |
コンパイル時間 | 2,908 ms |
コンパイル使用メモリ | 232,844 KB |
実行使用メモリ | 1,577,480 KB |
最終ジャッジ日時 | 2024-11-21 00:31:52 |
合計ジャッジ時間 | 55,277 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
13,640 KB |
testcase_01 | MLE | - |
testcase_02 | TLE | - |
testcase_03 | MLE | - |
testcase_04 | AC | 51 ms
13,736 KB |
testcase_05 | AC | 22 ms
467,364 KB |
testcase_06 | AC | 38 ms
13,632 KB |
testcase_07 | AC | 19 ms
417,576 KB |
testcase_08 | AC | 5 ms
13,636 KB |
testcase_09 | MLE | - |
testcase_10 | AC | 24 ms
13,636 KB |
testcase_11 | MLE | - |
testcase_12 | AC | 9 ms
13,636 KB |
testcase_13 | MLE | - |
testcase_14 | TLE | - |
testcase_15 | MLE | - |
testcase_16 | TLE | - |
testcase_17 | MLE | - |
testcase_18 | AC | 2,502 ms
175,648 KB |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | MLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; // const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt< mod >; int main() { int N, K; cin >> N >> K; int a, b, c, d; cin >> a >> b >> c >> d; auto dp = make_v< int >(K, 5, 5, 5, 5, 2); fill_v(dp, -1); auto tap = [](int a, int b, int c, int d) { vector< tuple< int, int, int, int > > uku; if(a && c) uku.emplace_back(a, b, (a + c) % 5, d); if(b && c) uku.emplace_back(a, b, (b + c) % 5, d); if(a && d) uku.emplace_back(a, b, c, (a + d) % 5); if(b && d) uku.emplace_back(a, b, c, (b + d) % 5); for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++) { bool ok = false; if(i + j == a + b) ok = true; if(i + j == (a + b) % 5) ok = true; if(i == a && j == b) ok = false; if(i == b && j == a) ok = false; if(ok) uku.emplace_back(i, j, c, d); } } return uku; }; vector< tuple< int, int, int, int > > beet; auto rec = MFP([&](auto rec, int a, int b, int c, int d, int turn, bool which) -> int { if((a + b) == 0) return 0; if((c + d) == 0) return 1; if(turn >= K) return 0; if(~dp[turn][a][b][c][d][which]) return dp[turn][a][b][c][d][which]; int ret = 0; if(which) { vector< tuple< int, int, int, int > > uku; if(a && c) uku.emplace_back((a + c) % 5, b, c, d); if(a && d) uku.emplace_back((a + d) % 5, b, c, d); if(b && c) uku.emplace_back(a, (b + c) % 5, c, d); if(b && d) uku.emplace_back(a, (b + d) % 5, c, d); for(int i = 0; i < 5; i++) { for(int j = 0; j < 5; j++) { bool ok = false; if(i + j == c + d) ok = true; if(i + j == (c + d) % 5) ok = true; if(i == c && j == d) ok = false; if(i == d && j == c) ok = false; if(ok) uku.emplace_back(a, b, i, j); } } for(auto &p : uku) { int r, t, y, u; tie(r, t, y, u) = p; if((y + u) == 0) continue; if((r + t) == 0) return 0; } bool exist = false; for(auto &p : uku) { int r, t, y, u; tie(r, t, y, u) = p; if((y + u) == 0) continue; bool ok = true; { auto get = tap(r, t, y, u); for(auto &q : get) { int aa, bb, cc, dd; tie(aa, bb, cc, dd) = q; if((cc + dd) == 0) ok = false; } } if(!ok) continue; exist = true; beet.emplace_back(p); ret += rec(r, t, y, u, turn + 1, which ^ 1); beet.pop_back(); ret %= mod; } if(!exist) { for(auto &p : uku) { int r, t, y, u; tie(r, t, y, u) = p; if((y + u) == 0) continue; beet.emplace_back(p); ret += rec(r, t, y, u, turn + 1, which ^ 1); beet.pop_back(); ret %= mod; exist = true; } } } else { auto get = tap(a, b, c, d); for(auto &p : get) { int r, t, y, u; tie(r, t, y, u) = p; if((r + t) == 0) continue; beet.emplace_back(p); ret += rec(r, t, y, u, turn + 1, which ^ 1); beet.pop_back(); ret %= mod; } } return dp[turn][a][b][c][d][which] = ret; }); cout << rec(a, b, c, d, 0, N) << endl; }