結果

問題 No.3724 Domination
コンテスト
ユーザー mono
提出日時 2026-09-19 15:05:52
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 4,296 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,980 ms
コンパイル使用メモリ 316,644 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2026-09-19 15:06:21
合計ジャッジ時間 18,026 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 20 % AC * 8
満点 80 % AC * 50 WA * 2
合計 2.5 * 20% = 50 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstdint>
#include <queue>
#include <tuple>
#include <cassert>
#include <atcoder/all>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
using ll = int64_t; using ull = uint64_t;
using vl = vector<ll>; using vvl = vector<vl>;using vvvl = vector<vvl>;
using vb = vector<bool>; using vvb = vector<vb>;using vvvb = vector<vvb>;
using vs = vector<string>; using vvs=vector<vector<string>>;
using pl = pair<ll,ll>; using vpl = vector<pl>;using vvpl = vector<vpl>;
using tl = tuple<ll,ll,ll>; using vtl = vector<tl>;using vvtl = vector<vector<tl>>;
using sl = set<ll>; using vsl = vector<sl>; using vvsl = vector<vsl>;
using ml = map<ll,ll>; using vml = vector<ml>; using vvml = vector<vml>;
using usl = unordered_set<ll>; using vusl = vector<usl>; using vvusl = vector<vusl>;
using uml = unordered_map<ll,ll>; using vuml = vector<uml>; using vvuml = vector<vuml>;
using mint = atcoder::modint998244353; 
using vm = vector<mint>; using vvm = vector<vector<mint>>; using vvvm = vector<vvm>;
#define rep1(a) for (ll _ = 0; _ < ll(a); ++_)
#define rep2(i, a) for (ll i = 0; i < ll(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define rrep1(a) for (ll i = (a)-1; i >= ll(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload3(a, b, c, d, ...) d
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload3(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define in(i,vec) for (auto i:(vec))
#define siz(a) ll(a.size())
void YesNo(bool a){cout<<(a?"Yes\n":"No\n");}
template<class T> using pqueue = priority_queue<T, vector<T>>;//大きい順
template<class T> using pqueue_g = priority_queue<T, vector<T>, greater<T>>;//小さい順
template<class T> bool chmin(T& x, T y){if(x>y){x=y;return true;}else return false;}
template<class T> bool chmax(T& x, T y){if(x<y){x=y;return true;}else return false;}
template<class T> void sor(vector<T>& v){sort(v.begin(),v.end());}
template<class T> void sor_g(vector<T>& v){sort(v.begin(),v.end(),greater<>());}
template<class T> void vin(vector<T>& v){size_t N = v.size();for(size_t i=0;i<N;++i)cin>>v[i];}
template<class T> void vvin(vector<vector<T>>& v){size_t N=v.size(),M=v[0].size();for(size_t i=0;i<N;++i)for(size_t j=0;j<M;++j)cin>>v[i][j];}
template<class T> T max(const vector<T>& v){return *max_element(v.begin(),v.end());}
template<class T> T min(const vector<T>& v){return *min_element(v.begin(),v.end());}
pair<int,int> d1{1,0},d2{0,1},d3{-1,0},d4{0,-1},d5{1,1},d6{-1,1},d7{1,-1},d8{-1,-1};
ll inf = 1e18;
int infi = 1e9;

pl op(pl a,pl b){return min(a,b);}
pl e(){return {inf,inf};}

void solve(){
    ll N; cin>>N;
    vpl R(N),C(N);
    rep(i,N){
        ll r; cin>>r; --r;
        R[i]={r,i};
    }
    rep(i,N){
        ll c; cin>>c; --c;
        C[i]={c,i};
    }
    sor(R);
    sor(C);

    if(N==1){
        if(R[0].first == C[0].first){cout << 1 << endl;}
        else cout << -1 << endl;
        return; 
    }else if(N==2){
        cout << -1 << endl;
        return;
    }
    if(N==3 && C[0].first == C[N-1].first){
        cout << -1 << endl;
        return;
    }
    if(N==4 && C[0].first == C[N-1].first){
        cout << -1 << endl;
        return;
    }
    

    atcoder::segtree<pl,op,e> seg(N);
    rep(i,N)seg.set(i,{0,i});

    vvl A(N,vl(N,0));
    rep(i,N)rep(j,N){
        A[i][j]=R[i].first;
    }

    ll t=0;

    rep(i,N){
        ll c = C[i].first;
        
        // pl tt = op(seg.prod(0,c),seg.prod(c+1,N));
        // ll t = tt.second;
        if(c==t)t=(t+1)%N;

        A[t][i]=c;
        // seg.set(t,{tt.first+1,tt.second});
        t=(t+1)%N;
    }

    // rep(i,N){
    //     rep(j,N)cerr<<A[i][j]+1<< " ";
    //     cerr << endl;
    // }
    // cerr << endl;

    vvl B(N,vl(N,-100));
    rep(i,N)rep(j,N){
        ll x = R[i].second, y=C[j].second;
        B[x][y]=A[i][j];
    }
    rep(i,N){
        rep(j,N)cout<<B[i][j]+1<< " ";
        cout << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll T; cin>>T;
    rep(T)solve();
}
0