結果
問題 | No.1776 Love Triangle 2 (Hard) |
ユーザー | HIR180 |
提出日時 | 2022-12-07 10:41:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 518 ms / 10,000 ms |
コード長 | 2,658 bytes |
コンパイル時間 | 2,790 ms |
コンパイル使用メモリ | 232,880 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-10-13 18:11:47 |
合計ジャッジ時間 | 21,312 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,760 KB |
testcase_01 | AC | 3 ms
5,760 KB |
testcase_02 | AC | 4 ms
5,632 KB |
testcase_03 | AC | 4 ms
5,760 KB |
testcase_04 | AC | 39 ms
5,888 KB |
testcase_05 | AC | 75 ms
5,888 KB |
testcase_06 | AC | 71 ms
5,760 KB |
testcase_07 | AC | 36 ms
5,760 KB |
testcase_08 | AC | 47 ms
5,760 KB |
testcase_09 | AC | 11 ms
5,760 KB |
testcase_10 | AC | 13 ms
5,760 KB |
testcase_11 | AC | 9 ms
5,760 KB |
testcase_12 | AC | 8 ms
5,888 KB |
testcase_13 | AC | 8 ms
5,888 KB |
testcase_14 | AC | 7 ms
5,760 KB |
testcase_15 | AC | 8 ms
5,760 KB |
testcase_16 | AC | 6 ms
5,760 KB |
testcase_17 | AC | 7 ms
5,760 KB |
testcase_18 | AC | 9 ms
5,632 KB |
testcase_19 | AC | 12 ms
5,888 KB |
testcase_20 | AC | 11 ms
5,760 KB |
testcase_21 | AC | 10 ms
5,888 KB |
testcase_22 | AC | 8 ms
5,760 KB |
testcase_23 | AC | 7 ms
5,760 KB |
testcase_24 | AC | 8 ms
5,760 KB |
testcase_25 | AC | 8 ms
5,760 KB |
testcase_26 | AC | 8 ms
5,760 KB |
testcase_27 | AC | 8 ms
5,760 KB |
testcase_28 | AC | 8 ms
5,760 KB |
testcase_29 | AC | 9 ms
5,760 KB |
testcase_30 | AC | 14 ms
6,016 KB |
testcase_31 | AC | 36 ms
5,760 KB |
testcase_32 | AC | 63 ms
5,760 KB |
testcase_33 | AC | 86 ms
5,760 KB |
testcase_34 | AC | 91 ms
5,760 KB |
testcase_35 | AC | 89 ms
5,888 KB |
testcase_36 | AC | 84 ms
6,016 KB |
testcase_37 | AC | 81 ms
5,760 KB |
testcase_38 | AC | 33 ms
5,760 KB |
testcase_39 | AC | 9 ms
5,760 KB |
testcase_40 | AC | 25 ms
5,888 KB |
testcase_41 | AC | 39 ms
5,760 KB |
testcase_42 | AC | 42 ms
5,760 KB |
testcase_43 | AC | 39 ms
5,760 KB |
testcase_44 | AC | 18 ms
5,760 KB |
testcase_45 | AC | 104 ms
5,760 KB |
testcase_46 | AC | 27 ms
5,888 KB |
testcase_47 | AC | 6 ms
5,760 KB |
testcase_48 | AC | 26 ms
5,888 KB |
testcase_49 | AC | 6 ms
5,888 KB |
testcase_50 | AC | 12 ms
5,888 KB |
testcase_51 | AC | 29 ms
5,760 KB |
testcase_52 | AC | 56 ms
5,760 KB |
testcase_53 | AC | 73 ms
5,760 KB |
testcase_54 | AC | 73 ms
5,760 KB |
testcase_55 | AC | 78 ms
5,760 KB |
testcase_56 | AC | 100 ms
5,760 KB |
testcase_57 | AC | 64 ms
5,760 KB |
testcase_58 | AC | 105 ms
5,760 KB |
testcase_59 | AC | 9 ms
5,760 KB |
testcase_60 | AC | 19 ms
5,760 KB |
testcase_61 | AC | 27 ms
5,888 KB |
testcase_62 | AC | 14 ms
5,760 KB |
testcase_63 | AC | 14 ms
5,760 KB |
testcase_64 | AC | 22 ms
5,760 KB |
testcase_65 | AC | 7 ms
5,760 KB |
testcase_66 | AC | 12 ms
5,760 KB |
testcase_67 | AC | 18 ms
5,888 KB |
testcase_68 | AC | 8 ms
5,760 KB |
testcase_69 | AC | 120 ms
5,888 KB |
testcase_70 | AC | 235 ms
5,760 KB |
testcase_71 | AC | 230 ms
5,760 KB |
testcase_72 | AC | 115 ms
5,760 KB |
testcase_73 | AC | 154 ms
5,760 KB |
testcase_74 | AC | 21 ms
5,888 KB |
testcase_75 | AC | 15 ms
5,888 KB |
testcase_76 | AC | 14 ms
5,888 KB |
testcase_77 | AC | 12 ms
5,760 KB |
testcase_78 | AC | 11 ms
5,760 KB |
testcase_79 | AC | 10 ms
5,760 KB |
testcase_80 | AC | 10 ms
5,760 KB |
testcase_81 | AC | 9 ms
5,760 KB |
testcase_82 | AC | 10 ms
5,760 KB |
testcase_83 | AC | 14 ms
5,760 KB |
testcase_84 | AC | 19 ms
5,760 KB |
testcase_85 | AC | 16 ms
5,760 KB |
testcase_86 | AC | 13 ms
5,888 KB |
testcase_87 | AC | 11 ms
5,760 KB |
testcase_88 | AC | 11 ms
5,760 KB |
testcase_89 | AC | 14 ms
5,888 KB |
testcase_90 | AC | 12 ms
5,760 KB |
testcase_91 | AC | 11 ms
5,760 KB |
testcase_92 | AC | 13 ms
5,760 KB |
testcase_93 | AC | 12 ms
5,760 KB |
testcase_94 | AC | 17 ms
5,888 KB |
testcase_95 | AC | 40 ms
5,760 KB |
testcase_96 | AC | 119 ms
5,760 KB |
testcase_97 | AC | 301 ms
5,760 KB |
testcase_98 | AC | 384 ms
5,760 KB |
testcase_99 | AC | 391 ms
5,760 KB |
testcase_100 | AC | 415 ms
5,760 KB |
testcase_101 | AC | 342 ms
5,760 KB |
testcase_102 | AC | 327 ms
5,760 KB |
testcase_103 | AC | 113 ms
5,888 KB |
testcase_104 | AC | 15 ms
5,760 KB |
testcase_105 | AC | 48 ms
5,760 KB |
testcase_106 | AC | 110 ms
5,632 KB |
testcase_107 | AC | 29 ms
5,888 KB |
testcase_108 | AC | 115 ms
5,760 KB |
testcase_109 | AC | 33 ms
5,760 KB |
testcase_110 | AC | 32 ms
5,760 KB |
testcase_111 | AC | 31 ms
5,760 KB |
testcase_112 | AC | 18 ms
5,760 KB |
testcase_113 | AC | 38 ms
5,760 KB |
testcase_114 | AC | 18 ms
5,760 KB |
testcase_115 | AC | 31 ms
5,760 KB |
testcase_116 | AC | 102 ms
5,760 KB |
testcase_117 | AC | 237 ms
5,760 KB |
testcase_118 | AC | 342 ms
5,888 KB |
testcase_119 | AC | 340 ms
5,760 KB |
testcase_120 | AC | 387 ms
5,888 KB |
testcase_121 | AC | 264 ms
5,760 KB |
testcase_122 | AC | 423 ms
5,760 KB |
testcase_123 | AC | 518 ms
5,760 KB |
testcase_124 | AC | 19 ms
5,888 KB |
testcase_125 | AC | 23 ms
5,760 KB |
testcase_126 | AC | 39 ms
5,760 KB |
testcase_127 | AC | 28 ms
5,760 KB |
testcase_128 | AC | 24 ms
5,888 KB |
testcase_129 | AC | 18 ms
5,760 KB |
testcase_130 | AC | 20 ms
5,760 KB |
testcase_131 | AC | 22 ms
5,888 KB |
testcase_132 | AC | 22 ms
5,760 KB |
testcase_133 | AC | 21 ms
5,760 KB |
testcase_134 | AC | 18 ms
5,760 KB |
testcase_135 | AC | 61 ms
5,760 KB |
testcase_136 | AC | 58 ms
5,760 KB |
testcase_137 | AC | 49 ms
5,888 KB |
testcase_138 | AC | 73 ms
5,888 KB |
testcase_139 | AC | 124 ms
5,888 KB |
testcase_140 | AC | 98 ms
5,760 KB |
testcase_141 | AC | 57 ms
5,760 KB |
testcase_142 | AC | 101 ms
5,760 KB |
testcase_143 | AC | 64 ms
5,760 KB |
testcase_144 | AC | 16 ms
5,760 KB |
testcase_145 | AC | 18 ms
5,760 KB |
testcase_146 | AC | 40 ms
5,760 KB |
testcase_147 | AC | 18 ms
5,760 KB |
testcase_148 | AC | 35 ms
5,760 KB |
testcase_149 | AC | 30 ms
5,760 KB |
testcase_150 | AC | 41 ms
5,760 KB |
testcase_151 | AC | 19 ms
5,760 KB |
testcase_152 | AC | 33 ms
5,632 KB |
testcase_153 | AC | 50 ms
5,760 KB |
testcase_154 | AC | 33 ms
5,760 KB |
testcase_155 | AC | 185 ms
5,760 KB |
testcase_156 | AC | 265 ms
5,760 KB |
testcase_157 | AC | 142 ms
5,888 KB |
testcase_158 | AC | 177 ms
5,760 KB |
testcase_159 | AC | 201 ms
5,760 KB |
testcase_160 | AC | 90 ms
5,888 KB |
testcase_161 | AC | 128 ms
5,760 KB |
testcase_162 | AC | 354 ms
5,760 KB |
testcase_163 | AC | 416 ms
5,760 KB |
testcase_164 | AC | 395 ms
5,888 KB |
testcase_165 | AC | 150 ms
5,760 KB |
testcase_166 | AC | 81 ms
5,888 KB |
testcase_167 | AC | 79 ms
5,888 KB |
testcase_168 | AC | 46 ms
5,888 KB |
testcase_169 | AC | 75 ms
5,760 KB |
testcase_170 | AC | 126 ms
5,760 KB |
testcase_171 | AC | 193 ms
5,760 KB |
testcase_172 | AC | 102 ms
5,760 KB |
testcase_173 | AC | 303 ms
5,760 KB |
testcase_174 | AC | 109 ms
5,760 KB |
testcase_175 | AC | 126 ms
5,760 KB |
ソースコード
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define pb push_back #define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define si(x) int(x.size()) template<class t> using vc=vector<t>; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); using ull=unsigned long long; //source: https://yukicoder.me/problems/no/1901 #pragma GCC target("pclmul", "sse2", "sse4.1") #include <emmintrin.h> #include <smmintrin.h> #include <wmmintrin.h> //mod x^63+x+1 ull nim_product(ull x, ull y) { __m128i x_ = _mm_set_epi64x(0, x); __m128i y_ = _mm_set_epi64x(0, y); __m128i z_ = _mm_clmulepi64_si128(x_, y_, 0); ull sm = _mm_extract_epi64(z_, 0); ull bg = _mm_extract_epi64(z_, 1); ull ret = (sm^(bg<<1)^(bg<<2)); if(ret&(1ull<<63)) ret^=((1ull<<63)^3); return ret; } constexpr int NL=150; ull dp[3*NL+5][NL+5][4], cs[NL+5][NL+5]; int n,m,x,y,z; bool bad[NL+5][NL+5], rem[NL+5]; int main(){ ios::sync_with_stdio(0); cin>>n>>m; cin>>x>>y>>z; x--;y--;z--; rep(i,n) bad[i][i]=true; rep(i,m){ int a,b;cin>>a>>b; a--;b--; bad[a][b]=bad[b][a]=true; } rep(i, n) rep(j, i) if(!bad[i][j]){ cs[i][j] = cs[j][i] = mt()>>1; } int goal = x, need = -1, M = 3; vc<int>ans{x}; rem[x] = true; while(need != 1){ memset(dp, 0, sizeof(dp)); dp[x][1][0] = 1; repn(len, n){ rep(state, 3*n){ rep(mask, 4){ if(dp[state][len][mask] == 0) continue; int pre=-1, now=state; if(state>=n){ pre=state%n; if(state/n==1)now=y; else now=z; } rep(nxt, n){ if(pre == nxt or rem[nxt] or bad[now][nxt]) continue; if(nxt == y and (mask&1)) continue; if(nxt == z and (mask&2)) continue; int nstate = nxt, nmask = mask; if(nxt == y) nstate = n+now, nmask|=1; else if(nxt == z) nstate = n+n+now, nmask|=2; dp[nstate][len+1][nmask] ^= nim_product(dp[state][len][mask], cs[now][nxt]); } } } if(need == -1 or need == len){ rep(now, n){ if(bad[now][goal] or rem[now]) continue; int lb=now, ub=now; if(now == y) lb=n, ub=2*n-1; else if(now == z) lb = 2*n, ub=3*n-1; rng(state, lb, ub+1){ if(dp[state][len][M]){ ans.pb(now); need = len-1; if(now==y) M^=1; else if(now==z) M^=2; goal = now; rem[goal] = true; goto nxt; } } } } } cout<<-1<<'\n'; return 0; nxt:; } cout<<si(ans)<<'\n'; for(auto e:ans) cout << ++e << " "; cout<<++x<<'\n'; }