結果
| 問題 | No.3724 Domination |
| コンテスト | |
| ユーザー |
shinchan
|
| 提出日時 | 2026-09-19 15:36:42 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 3,033 bytes |
| 記録 | |
| コンパイル時間 | 2,555 ms |
| コンパイル使用メモリ | 356,656 KB |
| 実行使用メモリ | 56,196 KB |
| 最終ジャッジ日時 | 2026-09-19 15:37:01 |
| 合計ジャッジ時間 | 18,504 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 20 % | AC * 7 WA * 1 |
| 満点 | 80 % | AC * 51 WA * 1 |
| 合計 | 2.5 * 0% = 0 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb emplace_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define foa(e, v) for(auto& e : v)
#define dout(a) cout<<fixed<<setprecision(10)<<a<<'\n';
#define Cout(a) cout<<a<<'\n';
using ll = long long;
using ld = long double;
using Int = __int128;
template <class T> using pqr = priority_queue<T, vector<T>, greater<T>>;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
bool compare = a < b;
if(compare) a = b;
return compare;
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
bool compare = a > b;
if(compare) a = b;
return compare;
}
template <typename T> inline T back(std::set<T> &s) {
return *s.rbegin();
}
template <typename T> inline T back(std::multiset<T> &s) {
return *s.rbegin();
}
template <typename T> inline T pop_back(std::set<T> &s) {
auto it = prev(s.end());
T val = *it;
s.erase(it);
return val;
}
template <typename T> inline T pop_back(std::multiset<T> &s) {
auto it = prev(s.end());
T val = *it;
s.erase(it);
return val;
}
const int dy[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
const int dx[8] = {0, -1, 1, 0, -1, -1, 1, 1};
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (3LL << 59);
const int inf = 1 << 30;
const char br = '\n';
#include<atcoder/maxflow>
using namespace atcoder;
void solve() {
int n; cin >> n;
vector<int> r(n), c(n), inv(n);
rep(i, n) {
cin >> r[i];
r[i] --;
inv[r[i]] = i;
}
rep(i, n) {
cin >> c[i];
c[i] --;
// c[i] = inv[c[i]];
}
if(n == 2) {
cout << -1 << endl;
return;
}
vector a(n, vector(n, 0));
rep(i, n) rep(j, n) {
a[i][j] = r[i];
}
{
set<int> st;
foa(e, c) st.insert(e);
if((int)st.size() == 1) {
if(n <= 4) {
cout << -1 << endl;
return;
}
int cnt = 0;
rep(i, n) if(r[i] != c[i]) {
a[i][cnt] = a[i][cnt + 1] = c[i];
cnt ++;
}
rep(i, n) {
foa(e, a[i]) cout << e + 1 << " ";
cout << endl;
}
return;
}
}
mf_graph<int> g(n + n + 2);
int S = n + n;
int T = S + 1;
rep(i, n) {
g.add_edge(S, i, 1);
g.add_edge(i + n, T, 1);
rep(j, n) {
if(r[i] != c[j]) g.add_edge(i, j + n, 1);
}
}
int num = g.flow(S, T);
assert(num == n);
auto edges = g.edges();
for(auto e: edges) {
if(e.flow == 0 or e.from == S or e.to == T) {
continue;
}
a[e.from][e.to - n] = c[e.to - n];
}
rep(i, n) {
foa(e, a[i]) cout << e + 1 << " ";
cout << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int testcase = 1;
cin >> testcase;
while(testcase --) solve();
return 0;
}
shinchan