結果
問題 |
No.3131 Twin Slide Puzzles
|
ユーザー |
![]() |
提出日時 | 2025-04-25 23:53:39 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 489 ms / 4,000 ms |
コード長 | 1,989 bytes |
コンパイル時間 | 3,748 ms |
コンパイル使用メモリ | 287,160 KB |
実行使用メモリ | 78,296 KB |
最終ジャッジ日時 | 2025-06-20 02:49:02 |
合計ジャッジ時間 | 22,207 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 59 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; constexpr ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; vector<ll> a(n*n); rep(i,n*n) cin >> a[i]; ll f=min(n*n,16ll); vector<ll> p(f); rep(i,f) p[i]=i; unordered_map<ll,vector<ll>> mp; do{ vector<ll> pos(f,0),v=p; ll zero=0; rep(i,f){ pos[v[i]]=i; if(v[i]==0) zero=i/n+i%n; } ll cnt=0; rep(i,f){ if(v[i]!=i){ ll x=v[i]; swap(v[i],v[pos[i]]); swap(pos[i],pos[x]); cnt++; } } if(zero%2!=cnt%2) continue; ll sum=0; rep(i,f){ sum+=a[i]*p[i]; } if(mp.contains(sum)){ vector<ll> q=mp[sum]; vector<ll> x(n*n),y(n*n); rep(i,n*n) x[i]=y[i]=i; rep(i,f) x[i]=p[i]; rep(i,f) y[i]=q[i]; cout << "Yes\n"; rep(i,n){ rep(j,n){ cout << x[i*n+j] << ' '; } cout << '\n'; } rep(i,n){ rep(j,n){ cout << y[i*n+j] << ' '; } cout << '\n'; } return 0; }else{ mp[sum]=p; } }while(next_permutation(all(p))); cout << "No\n"; }