結果
| 問題 | No.3724 Domination |
| コンテスト | |
| ユーザー |
caz37OwO
|
| 提出日時 | 2026-09-30 12:48:34 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 181 ms / 2,000 ms |
| + 309µs | |
| コード長 | 3,055 bytes |
| 記録 | |
| コンパイル時間 | 7,251 ms |
| コンパイル使用メモリ | 392,132 KB |
| 実行使用メモリ | 9,868 KB |
| 最終ジャッジ日時 | 2026-09-30 12:48:58 |
| 合計ジャッジ時間 | 23,411 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 20 % | AC * 8 |
| 満点 | 80 % | AC * 52 |
| 合計 | 2.5 * 100% = 250 点 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ldub=long double;
using lldub=__float128;
using str=string;
using mint=modint;
template<class T=ll>
using tup2=tuple<T,T>;
template<class T=ll>
using tup3=tuple<T,T,T>;
template<class T=ll>
using tup4=tuple<T,T,T,T>;
template<class T=ll>
using tup5=tuple<T,T,T,T,T>;
template<class T=ll>
using tup6=tuple<T,T,T,T,T,T>;
template<class T=ll>
using tup7=tuple<T,T,T,T,T,T,T>;
template<class T=ll>
using vec=vector<T>;
template<class T=ll>
using vec2=vector<vec<T>>;
template<class T=ll>
using vec3=vector<vec2<T>>;
template<class T=ll>
using vec4=vector<vec3<T>>;
template<class T=ll>
using vec5=vector<vec4<T>>;
template<class T=ll>
using vec6=vector<vec5<T>>;
template<class T>
using que=queue<T>;
template<class T>
using Pque=priority_queue<T>;
template<class T>
using pque=priority_queue<T, vector<T>, greater<T>>;
struct Edge{
ll from,to,w=1,num=-1;
};
using gvec=vector<Edge>;
using gvec2=vector<gvec>;
template<class T>
bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ins insert
#define tup make_tuple
#define low lower_bound
#define pops(a) __builtin_popcountll(a)
#define ctz(a) __builtin_ctzll(a)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define nperm(v) next_permutation(all(v))
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YN(f) cout << ((f)?"Yes":"No") << endl
const int IINF=2e9;
const ll INF=4e18;
#ifndef LOCAL
#define debug(x)
#endif
// =================================================
void solve(){
ll N;
cin >> N;
vec R(N),C(N);
for(ll i=0;i<N;i++) cin >> R[i],R[i]--;
for(ll j=0;j<N;j++) cin >> C[j],C[j]--;
vec2 A(N,vec(N,-1));
if(N==1){
A[0][0]=0;
}else if(N==2){
cout << -1 << endl;
return;
}else if(N==3||N==4){
if(*max_element(all(C))==*min_element(all(C))){
cout << -1 << endl;
return;
}
vec P(N);
iota(all(P),0);
do{
ll f=1;
for(ll i=0;i<N;i++) if(P[i]==C[i]) f=0;
if(f) break;
}while(nperm(P));
for(ll i=0;i<N;i++){
for(ll j=0;j<N;j++){
if(P[j]==R[i]) continue;
A[i][j]=R[i];
}
}
for(ll j=0;j<N;j++){
for(ll i=0;i<N;i++){
if(A[i][j]!=-1) continue;
A[i][j]=C[j];
}
}
}else{
for(ll i=0;i<N;i++){
for(ll j=0;j<N;j++){
if((i-j+N)%N<=1) continue;
A[i][j]=R[i];
}
}
for(ll j=0;j<N;j++){
for(ll i=0;i<N;i++){
if(A[i][j]!=-1) continue;
A[i][j]=C[j];
}
}
}
for(ll i=0;i<N;i++){
for(ll j=0;j<N;j++) cout << A[i][j]+1 << ' ';
cout << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
mint::set_mod(998244353);
// mint::set_mod(1000000007);
ll T=1;
cin >> T;
while(T--) solve();
return 0;
}
caz37OwO