結果
| 問題 | No.3732 Labyrinth Maker |
| コンテスト | |
| ユーザー |
てんぷら
|
| 提出日時 | 2026-09-19 14:45:33 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,749 bytes |
| 記録 | |
| コンパイル時間 | 2,151 ms |
| コンパイル使用メモリ | 345,472 KB |
| 実行使用メモリ | 34,644 KB |
| 最終ジャッジ日時 | 2026-09-19 14:46:07 |
| 合計ジャッジ時間 | 29,943 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 35 WA * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef TEMPURA
#else
#define debug(...) ((void)0)
#define msg(...) ((void)0)
#endif
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
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;
}
// #include <atcoder/modint>
// using mint = atcoder::modint998244353;
void solve() {
int n;
cin >> n;
vector<vector<int>> ords;
{
vector<int> ord;
rep(i, n) {
if(i % 2 == 0) {
rep(j, n) ord.push_back(i * n + j);
} else {
rep(j, n) ord.push_back(i * n + n - 1 - j);
}
}
ords.push_back(ord);
}
{
vector<int> ord;
rep(i, n) {
if(i % 2 == 1) {
rep(j, n) ord.push_back(i * n + j);
} else {
rep(j, n) ord.push_back(i * n + n - 1 - j);
}
}
ords.push_back(ord);
}
{
vector<int> ord;
rep(i, n) {
if(i % 2 == 0) {
rep(j, n) ord.push_back(j * n + i);
} else {
rep(j, n) ord.push_back((n - 1 - j) * n + i);
}
}
ords.push_back(ord);
}
{
vector<int> ord;
rep(i, n) {
if(i % 2 == 1) {
rep(j, n) ord.push_back(j * n + i);
} else {
rep(j, n) ord.push_back((n - 1 - j) * n + i);
}
}
ords.push_back(ord);
}
vector<int> a(n * n);
rep(i, n * n) cin >> a[i];
int s = 0;
rep(i, n * n) s += a[i];
if(s % n != 0) {
cout << -1 << endl;
return;
}
for(auto ord : ords) {
vector<int> sum(n * n + 1);
rep(i, n * n) {
sum[i + 1] = (sum[i] + a[ord[i]]) % n;
}
vector<int> cnt(n);
rep(i, n * n) {
cnt[sum[i]] += 1;
}
if(cnt[0] < n) {
continue;
}
vector<int> ans(n * n);
int cur = 1;
rep(i, n * n) {
ans[ord[i]] = cur;
if(sum[i + 1] == 0) {
cur = min(n, cur + 1);
}
}
rep(i, n * n) {
cout << ans[i] << " \n"[i % n == n - 1];
}
return;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) {
solve();
}
}
てんぷら