結果
問題 | No.1776 Love Triangle 2 (Hard) |
ユーザー | hitonanode |
提出日時 | 2021-11-19 19:58:05 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 7,043 bytes |
コンパイル時間 | 2,421 ms |
コンパイル使用メモリ | 149,920 KB |
実行使用メモリ | 11,804 KB |
最終ジャッジ日時 | 2024-07-02 12:00:49 |
合計ジャッジ時間 | 55,529 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
5,248 KB |
testcase_01 | AC | 32 ms
5,376 KB |
testcase_02 | AC | 32 ms
5,376 KB |
testcase_03 | AC | 33 ms
5,376 KB |
testcase_04 | AC | 86 ms
5,376 KB |
testcase_05 | AC | 88 ms
5,376 KB |
testcase_06 | AC | 88 ms
5,376 KB |
testcase_07 | AC | 87 ms
5,376 KB |
testcase_08 | AC | 89 ms
5,376 KB |
testcase_09 | AC | 1,941 ms
5,376 KB |
testcase_10 | AC | 2,461 ms
5,376 KB |
testcase_11 | AC | 1,042 ms
5,376 KB |
testcase_12 | AC | 855 ms
5,376 KB |
testcase_13 | AC | 499 ms
5,376 KB |
testcase_14 | AC | 365 ms
5,376 KB |
testcase_15 | AC | 250 ms
5,376 KB |
testcase_16 | AC | 214 ms
5,376 KB |
testcase_17 | AC | 170 ms
5,376 KB |
testcase_18 | AC | 158 ms
5,376 KB |
testcase_19 | AC | 1,669 ms
5,376 KB |
testcase_20 | AC | 1,536 ms
5,376 KB |
testcase_21 | AC | 1,043 ms
5,376 KB |
testcase_22 | AC | 751 ms
5,376 KB |
testcase_23 | AC | 490 ms
5,376 KB |
testcase_24 | AC | 1,054 ms
5,376 KB |
testcase_25 | AC | 742 ms
5,376 KB |
testcase_26 | AC | 507 ms
5,376 KB |
testcase_27 | AC | 770 ms
5,376 KB |
testcase_28 | AC | 405 ms
5,376 KB |
testcase_29 | AC | 147 ms
5,376 KB |
testcase_30 | AC | 521 ms
5,376 KB |
testcase_31 | AC | 1,976 ms
5,376 KB |
testcase_32 | AC | 4,326 ms
5,376 KB |
testcase_33 | AC | 8,125 ms
5,376 KB |
testcase_34 | AC | 8,182 ms
5,376 KB |
testcase_35 | TLE | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
testcase_68 | -- | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
testcase_71 | -- | - |
testcase_72 | -- | - |
testcase_73 | -- | - |
testcase_74 | -- | - |
testcase_75 | -- | - |
testcase_76 | -- | - |
testcase_77 | -- | - |
testcase_78 | -- | - |
testcase_79 | -- | - |
testcase_80 | -- | - |
testcase_81 | -- | - |
testcase_82 | -- | - |
testcase_83 | -- | - |
testcase_84 | -- | - |
testcase_85 | -- | - |
testcase_86 | -- | - |
testcase_87 | -- | - |
testcase_88 | -- | - |
testcase_89 | -- | - |
testcase_90 | -- | - |
testcase_91 | -- | - |
testcase_92 | -- | - |
testcase_93 | -- | - |
testcase_94 | -- | - |
testcase_95 | -- | - |
testcase_96 | -- | - |
testcase_97 | -- | - |
testcase_98 | -- | - |
testcase_99 | -- | - |
testcase_100 | -- | - |
testcase_101 | -- | - |
testcase_102 | -- | - |
testcase_103 | -- | - |
testcase_104 | -- | - |
testcase_105 | -- | - |
testcase_106 | -- | - |
testcase_107 | -- | - |
testcase_108 | -- | - |
testcase_109 | -- | - |
testcase_110 | -- | - |
testcase_111 | -- | - |
testcase_112 | -- | - |
testcase_113 | -- | - |
testcase_114 | -- | - |
testcase_115 | -- | - |
testcase_116 | -- | - |
testcase_117 | -- | - |
testcase_118 | -- | - |
testcase_119 | -- | - |
testcase_120 | -- | - |
testcase_121 | -- | - |
testcase_122 | -- | - |
testcase_123 | -- | - |
testcase_124 | -- | - |
testcase_125 | -- | - |
testcase_126 | -- | - |
testcase_127 | -- | - |
testcase_128 | -- | - |
testcase_129 | -- | - |
testcase_130 | -- | - |
testcase_131 | -- | - |
testcase_132 | -- | - |
testcase_133 | -- | - |
testcase_134 | -- | - |
testcase_135 | -- | - |
testcase_136 | -- | - |
testcase_137 | -- | - |
testcase_138 | -- | - |
testcase_139 | -- | - |
testcase_140 | -- | - |
testcase_141 | -- | - |
testcase_142 | -- | - |
testcase_143 | -- | - |
testcase_144 | -- | - |
testcase_145 | -- | - |
testcase_146 | -- | - |
testcase_147 | -- | - |
testcase_148 | -- | - |
testcase_149 | -- | - |
testcase_150 | -- | - |
testcase_151 | -- | - |
testcase_152 | -- | - |
testcase_153 | -- | - |
testcase_154 | -- | - |
testcase_155 | -- | - |
testcase_156 | -- | - |
testcase_157 | -- | - |
testcase_158 | -- | - |
testcase_159 | -- | - |
testcase_160 | -- | - |
testcase_161 | -- | - |
testcase_162 | -- | - |
testcase_163 | -- | - |
testcase_164 | -- | - |
testcase_165 | -- | - |
testcase_166 | -- | - |
testcase_167 | -- | - |
testcase_168 | -- | - |
testcase_169 | -- | - |
testcase_170 | -- | - |
testcase_171 | -- | - |
testcase_172 | -- | - |
testcase_173 | -- | - |
testcase_174 | -- | - |
testcase_175 | -- | - |
ソースコード
#include <array> #include <chrono> #include <iostream> #include <random> #include <vector> using namespace std; // https://epubs.siam.org/doi/10.1137/1.9781611973099.139 // Nimber (64 bit) // Reference: // - https://en.wikipedia.org/wiki/Nimber // - https://kyopro-friends.hatenablog.com/entry/2020/04/07/195850 // - https://judge.yosupo.jp/submission/4542 (implementation idea) struct Nimber { using ull = unsigned long long; ull v; const static std::array<std::array<unsigned, 256>, 256> small_table; const static std::array<std::array<std::array<ull, 256>, 8>, 8> precalc; explicit operator bool() const { return v != 0; } Nimber(ull val = 0) : v(val) {} Nimber operator+(const Nimber &x) const { return Nimber(v ^ x.v); } Nimber operator-(const Nimber &x) const { return Nimber(v ^ x.v); } Nimber operator-() const { return *this; } Nimber &operator+=(const Nimber &x) { return *this = *this + x; } Nimber &operator-=(const Nimber &x) { return *this = *this + x; } template <class IStream> friend IStream &operator>>(IStream &is, Nimber &x) { ull v; return is >> v, x = Nimber(v), is; } template <class OStream> friend OStream &operator<<(OStream &os, const Nimber &x) { return os << x.v; } bool operator==(const Nimber &x) const { return v == x.v; } bool operator!=(const Nimber &x) const { return v != x.v; } bool operator<(const Nimber &x) const { return v < x.v; } static ull _rec(ull x, ull y) { if (x == 0 or y == 0) return 0; if (x < y) x ^= y, y ^= x, x ^= y; // Make x >= y if (y == 1) return x; for (int shift = 64 / 2;; shift >>= 1) { ull mask = (1ULL << shift) - 1; if (y >> shift) { ull v00 = _rec(x & mask, y & mask); ull v01 = _rec(x & mask, y >> shift); ull v10 = _rec(x >> shift, y & mask); ull v11 = _rec(x >> shift, y >> shift); return v00 ^ ((v01 ^ v10 ^ v11) << shift) ^ _rec(v11, 1ULL << (shift - 1)); } else if (x >> shift) { return (_rec(x >> shift, y) << shift) ^ _rec(x & mask, y); } } } Nimber operator*(const Nimber &x) const { if (this->v < 256 and x.v < 256) return small_table[this->v][x.v]; ull ret = 0; for (int d = 0; d < 2; ++d) { // 16 bit for (int e = 0; e < 2; ++e) { // 16 bit ret ^= precalc[d][e][small_table[(v >> (d * 8)) & 255][(x.v >> (e * 8)) & 255]]; } } return Nimber(ret); } Nimber &operator*=(const Nimber &x) { return *this = *this * x; } }; const std::array<std::array<unsigned, 256>, 256> Nimber::small_table = []() { std::array<std::array<unsigned, 256>, 256> ret; for (int i = 0; i < 256; ++i) { for (int j = 0; j < 256; ++j) ret[i][j] = _rec(i, j); } return ret; }(); const std::array<std::array<std::array<unsigned long long, 256>, 8>, 8> Nimber::precalc = []() { std::array<std::array<std::array<unsigned long long, 256>, 8>, 8> ret; for (int d = 0; d < 8; ++d) { for (int e = 0; e < 8; ++e) { ull p = _rec(1ULL << (8 * d), 1ULL << (8 * e)); for (int i = 0; i < 256; ++i) ret[d][e][i] = _rec(p, i); } } return ret; }(); struct rand_int_ { using lint = long long; mt19937 mt; rand_int_() : mt(chrono::steady_clock::now().time_since_epoch().count()) {} lint operator()(lint x) { return this->operator()(0, x); } // [0, x) lint operator()(lint l, lint r) { uniform_int_distribution<lint> d(l, r - 1); return d(mt); } } rnd; template <class Fq> int can_reach(const vector<vector<Fq>> &w, int x, int y, int z, int dlim) { // x を始点に y, z を経由し N に到達する長さ dlim 以下のパスがあるかを判定 int N = w.size() - 1; // dp[visited y][visited z][current v][previous v] vector dp(2, vector(2, vector(N + 1, vector<Fq>(N + 1, 0)))); dp[0][0][x][N] = 1; for (int d = 1; d <= dlim; ++d) { vector dpnxt(2, vector(2, vector(N + 1, vector<Fq>(N + 1, 0)))); for (int visy = 0; visy < 2; ++visy) { for (int visz = 0; visz < 2; ++visz) { for (int now = 0; now < N; ++now) { Fq sum = 0; for (int prv = 0; prv <= N; ++prv) sum += dp[visy][visz][now][prv]; for (int nxt = 0; nxt <= N; ++nxt) { if (visy and (nxt == y)) continue; if (visz and (nxt == z)) continue; dpnxt[visy | (nxt == y)][visz | (nxt == z)][nxt][now] += (sum - dp[visy][visz][now][nxt]) * w[now][nxt]; } } } } dp = dpnxt; for (int i = 0; i < N; ++i) { if (dp[1][1][N][i] != 0) return d; } } return 0; // not found } int main() { int N, M; cin >> N >> M; int x, y, z; cin >> x >> y >> z; --x, --y, --z; vector weight(N + 1, vector<Nimber>(N + 1)); for (int i = 0; i < N; ++i) { for (int j = 0; j < i; ++j) { Nimber w = rnd(1LL << 16); Nimber wn = rnd(1LL << 16); if (j != x) { weight[i][j] = w; } else { weight[i][N] = wn; } if (i != x) { weight[j][i] = w; } else { weight[j][N] = wn; } } } vector<vector<pair<int, Nimber>>> to(N); vector exist_edge(N, vector<int>(N, 1)); while (M--) { int a, b; cin >> a >> b; --a, --b; weight[a][b] = weight[b][a] = 0; if (a == x) weight[b][N] = 0; if (b == x) weight[a][N] = 0; } int len = can_reach(weight, x, y, z, N); if (!len) { puts("-1"); return 0; } cout << len << '\n'; vector<int> path{x}; for (int l = 1; l < len; ++l) { int ok = N, ng = -1; // ok 以下の頂点で到達可能、ng 以下の頂点で到達無理 while (ok - ng > 1) { int thres = (ok + ng) / 2; auto mat = weight; int cur = path.back(); int prv = -1; if (path.size() >= 2) prv = path[path.size() - 2]; for (int i = thres + 1; i <= N; ++i) { mat[cur][i] = mat[i][cur] = 0; } if (prv >= 0) mat[cur][prv] = mat[prv][cur] = 1; int cur_len = can_reach(mat, x, y, z, len); (cur_len == len ? ok : ng) = thres; } int cur = path.back(); int prv = -1; if (path.size() >= 2) prv = path[path.size() - 2]; path.push_back(ok); for (int i = 0; i <= N; ++i) { weight[cur][i] = weight[i][cur] = 0; } if (prv >= 0) weight[cur][prv] = weight[prv][cur] = 1; } path.push_back(x); for (auto x : path) cout << x + 1 << ' '; cout << '\n'; }