結果

問題 No.3131 Twin Slide Puzzles
ユーザー FplusFplusF
提出日時 2025-04-25 23:50:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,016 bytes
コンパイル時間 3,633 ms
コンパイル使用メモリ 288,512 KB
実行使用メモリ 78,188 KB
最終ジャッジ日時 2025-04-25 23:51:18
合計ジャッジ時間 20,505 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
        }
        if(zero%2!=0) continue;
        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(cnt%2!=0) 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";
}
0