結果
| 問題 |
No.3131 Twin Slide Puzzles
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-26 07:39:41 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,838 bytes |
| コンパイル時間 | 4,265 ms |
| コンパイル使用メモリ | 310,056 KB |
| 実行使用メモリ | 281,728 KB |
| 最終ジャッジ日時 | 2025-04-26 07:40:38 |
| 合計ジャッジ時間 | 26,344 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 TLE * 1 |
ソースコード
// #include <bits/allocator.h> // Temp fix for gcc13 global pragma
// #pragma GCC target("avx2,bmi2,popcnt,lzcnt")
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
#ifdef LOCAL
#include "Debug.h"
#else
#define debug_endl() 42
#define debug(...) 42
#define debug2(...) 42
#define debug_bin(...) 42
#endif
namespace direction_vectors{
vector<array<int, 2>> dr2{{1, 0}, {0, 1}};
vector<array<int, 2>> dr4{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
vector<array<int, 2>> dr4diag{{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
vector<array<int, 2>> dr8{{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
vector<array<int, 2>> drk{{2, 1}, {1, 2}, {-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1}};
vector<array<int, 2>> generate(int low, int high){
assert(0 <= low && low <= high);
int th = sqrt(high) + 1;
vector<array<int, 2>> dr;
for(auto x = -th; x <= th; ++ x) for(auto y = -th; y <= th; ++ y) if(auto d = x * x + y * y; low <= d && d <= high) dr.push_back({x, y});
return dr;
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
auto dr = direction_vectors::dr4;
int n;
cin >> n;
vector coef(n, vector<int>(n));
for(auto &x: coef | ranges::views::join){
cin >> x;
}
const int m = min(n, 4);
vector<int> a(m * m);
for(auto i = 0; i < m; ++ i){
for(auto j = 0; j < m; ++ j){
a[m * i + j] = n * i + j;
}
}
auto get_cost = [&](const vector<int> &a)->long long{
long long cost = 0;
for(auto i = 0; i < m; ++ i){
for(auto j = 0; j < m; ++ j){
cost += 1LL * coef[i][j] * a[m * i + j];
}
}
return cost;
};
set<vector<int>> found{a};
map<long long, vector<int>> mp;
mp[get_cost(a)] = a;
deque<vector<int>> dq{a};
while(!dq.empty()){
auto a = dq.front();
dq.pop_front();
int zi = -1, zj = -1;
for(auto i = 0; i < m; ++ i){
for(auto j = 0; j < m; ++ j){
if(a[m * i + j] == 0){
zi = i, zj = j;
goto DONE;
}
}
}
DONE:;
for(auto [di, dj]: dr){
int in = zi + di, jn = zj + dj;
if(0 <= min(in, jn) && max(in, jn) < m){
swap(a[m * zi + zj], a[m * in + jn]);
if(found.insert(a).second){
auto ca = get_cost(a);
if(!mp.insert({ca, a}).second){
auto b = mp[ca];
cout << "Yes\n";
for(auto rep = 2; rep; -- rep){
for(auto i = 0; i < n; ++ i){
for(auto j = 0; j < n; ++ j){
if(i < m && j < m){
cout << a[m * i + j] << " ";
}
else{
cout << n * i + j << " ";
}
}
cout << "\n";
}
swap(a, b);
}
return 0;
}
dq.push_back(a);
}
swap(a[m * zi + zj], a[m * in + jn]);
}
}
}
cout << "No\n";
return 0;
}
/*
*/