結果
| 問題 | No.3724 Domination |
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2026-10-03 11:16:39 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,446 bytes |
| 記録 | |
| コンパイル時間 | 2,476 ms |
| コンパイル使用メモリ | 340,184 KB |
| 実行使用メモリ | 9,924 KB |
| 最終ジャッジ日時 | 2026-10-03 11:16:56 |
| 合計ジャッジ時間 | 11,884 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge4_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 20 % | AC * 7 WA * 1 |
| 満点 | 80 % | AC * 23 WA * 29 |
| 合計 | 2.5 * 0% = 0 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int inf32 = numeric_limits<int>::max() / 2;
constexpr ll inf64 = numeric_limits<ll>::max() / 2;
template<typename T1, typename T2>
bool chmin(T1 &a, T2 b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
bool chmax(T1 &a, T2 b) { return a < b ? a = b, true : false; }
void solve() {
int N;
cin >> N;
vector<int> R(N), C(N);
for (auto &e : R) cin >> e, e--;
for (auto &e : C) cin >> e, e--;
vector<vector<int>> A(N, vector<int>(N));
auto rec = [&] (auto rec, int r, int c) -> bool {
if (r == N) {
bool ok = true;
for (int i = 0; i < N; i++) {
vector<int> cnt(N);
for (int j = 0; j < N; j++) cnt[A[i][j]]++;
int pos = max_element(cnt.begin(), cnt.end()) - cnt.begin();
if (count(cnt.begin(), cnt.end(), cnt[pos]) >= 2) ok = false;
if (pos != R[i]) ok = false;
}
for (int j = 0; j < N; j++) {
vector<int> cnt(N);
for (int i = 0; i < N; i++) cnt[A[i][j]]++;
int pos = max_element(cnt.begin(), cnt.end()) - cnt.begin();
if (count(cnt.begin(), cnt.end(), cnt[pos]) >= 2) ok = false;
if (pos != C[j]) ok = false;
}
return ok;
}
for (int a = 0; a < N; a++) {
A[r][c] = a;
int nr = r, nc = c + 1;
if (nc == N) nr = r + 1, nc = 0;
if (rec(rec, nr, nc)) return true;
}
return false;
};
if (N <= 3) {
if (rec(rec, 0, 0)) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout << A[i][j] << " \n"[j + 1 == N];
}
}
} else {
cout << -1 << '\n';
}
return;
}
for (int i = 0; i < N; i++) A[i] = vector<int>(N, R[i]);
for (int j = 0; j < N; j++) {
for (int i = 0; i < N; i++) {
if (A[i][j] == C[j]) {
A[(i + 1) % N][j] = C[j];
break;
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) cout << A[i][j] + 1 << " \n"[j + 1 == N];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) solve();
}
nonon