結果
問題 | No.1776 Love Triangle 2 (Hard) |
ユーザー |
![]() |
提出日時 | 2022-12-07 10:41:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 476 ms / 10,000 ms |
コード長 | 2,658 bytes |
コンパイル時間 | 2,298 ms |
コンパイル使用メモリ | 236,952 KB |
最終ジャッジ日時 | 2025-02-09 06:03:00 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 176 |
ソースコード
//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+1ull 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';}