結果
| 問題 |
No.3131 Twin Slide Puzzles
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-25 21:46:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,131 bytes |
| コンパイル時間 | 2,708 ms |
| コンパイル使用メモリ | 160,652 KB |
| 実行使用メモリ | 814,412 KB |
| 最終ジャッジ日時 | 2025-04-25 21:46:26 |
| 合計ジャッジ時間 | 13,645 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 19 WA * 13 MLE * 1 -- * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:136:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
136 | scanf("%lld", &A[i]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// cannot use count
// no move constructor (==> use pointer for merge tech)
// unordered_set by value: __gnu_pbds::null_type
// no erase(iterator)
#include <ext/pb_ds/assoc_container.hpp>
using __gnu_pbds::gp_hash_table;
// https://codeforces.com/blog/entry/62393
#include <chrono>
struct Hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
size_t operator()(const pair<int, int> &a) const {
return operator()((uint64_t)a.first << 32 | a.second);
}
};
template <class K> using Set = gp_hash_table<K, __gnu_pbds::null_type, Hash>;
template <class K, class V> using Map = gp_hash_table<K, V, Hash>;
#include <chrono>
#ifdef LOCAL
mt19937_64 rng(58);
#else
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
vector<int> uf;
int root(int u) {
return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return false;
if (uf[u] > uf[v]) swap(u, v);
uf[u] += uf[v];
uf[v] = u;
return true;
}
int N;
vector<Int> A;
pair<vector<int>, vector<int>> solve() {
uf.resize(N*N);
Map<Int, vector<int>> vis;
vector<int> ps(N*N), qs;
auto check = [&]() -> bool {
fill(uf.begin(), uf.end(), -1);
int sig = +1;
for (int i = 0; i < N*N; ++i) if (connect(i, ps[i])) sig = -sig;
if (sig < 0) return false;
Int sum = 0;
for (int i = 0; i < N*N; ++i) sum += A[i] * ps[i];
auto it = vis.find(sum);
if (it != vis.end()) {
if (ps == it->second) return false;
qs = it->second;
return true;
} else {
vis[sum] = ps;
return false;
}
};
for (int i = 0; i < N*N; ++i) ps[i] = i;
if (N <= 3) {
do {
if (check()) return make_pair(ps, qs);
} while (next_permutation(ps.begin(), ps.end()));
} else {
constexpr int L = 14;
for (; ; ) {
for (int i = 0; i < L; ++i) swap(ps[rng() % (i + 1)], ps[i] = i);
if (check()) return make_pair(ps, qs);
}
}
return {};
}
int main() {
for (; ~scanf("%d", &N); ) {
A.resize(N*N);
for (int i = 0; i < N*N; ++i) {
scanf("%lld", &A[i]);
}
const auto ans = solve();
if (ans.first.size()) {
puts("Yes");
for (const auto &ps : {ans.first, ans.second}) {
for (int x = 0; x < N; ++x) {
for (int y = 0; y < N; ++y) {
if (y) printf(" ");
printf("%d", ps[x * N + y]);
}
puts("");
}
}
} else {
puts("No");
}
}
return 0;
}