結果

問題 No.3724 Domination
コンテスト
ユーザー ammonitenh3
提出日時 2026-09-19 14:56:59
言語 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
結果
RE  
実行時間 -
コード長 3,298 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,482 ms
コンパイル使用メモリ 408,844 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2026-09-19 14:57:16
合計ジャッジ時間 16,485 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 20 % AC * 7 RE * 1
満点 80 % AC * 37 RE * 15
合計 2.5 * 0% = 0 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using mint = modint998244353;
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}

const ll inf=1000000000000000000;
const ll mod=998244353;
const double pi=acos(-1);

ll root(ll x){
    ll k=(ll)sqrt(x);
    while(k*k>x) k--;
    while((k+1)*(k+1)<=x) k++;
    return k;
}

//logN
void press(vector<ll> &a){
    map<ll,ll> ord;
    for(auto x:a) ord[x]=1;
    ll j=0;
    for(auto &p:ord){
        p.second=j;
        j++;
    }
    for(auto &x:a) x=ord[x];
    return;
}

mint kaijou(ll n){
    mint a=1;
    rep(i,n){
        a*=(i+1);
    }
    return a;
}

vector<vector<mint>> matmul(vector<vector<mint>> &a,vector<vector<mint>> &b){
    vector<vector<mint>> ret(a.size(),vector<mint>(b[0].size()));
    rep(i,a.size()) rep(j,b[0].size()) rep(k,b.size()) ret[i][j]+=a[i][k]*b[k][j];
    return ret;
}

vector<vector<mint>> matpow(vector<vector<mint>> a,ll n){
    ll siz=a.size();
    vector<vector<mint>> ret(siz,vector<mint>(siz));
    while(n>0){
        if(n&1) ret=matmul(a,ret);
        rep(i,siz) ret[i][i]=1;
        a=matmul(a,a);
        n=n/2;
    }
    return ret;
}

int main () {
    ll t;
    cin>>t;
    rep(ti,t){
        ll n;
        cin>>n;
        vector<pair<ll,ll>> r(n),c(n);
        rep(i,n) cin>>r[i].first;
        rep(i,n) cin>>c[i].first;
        if(n==2){
            cout<<-1<<endl;
            continue;
        }
        rep(i,n) {
            r[i].second=i;
            c[i].second=i;
        }
        sort(all(r));
        sort(all(c));
        vector<ll> a(n);
        rep(i,n) a[i]=c[i].first;
        vector<vector<ll>> ans(n,vector<ll>(n,-1));
        rep(i,n) rep(j,n) if(r[i].first==c[j].first) ans[i][j]=r[i].first;
        queue<ll> togo,amari;
        rep(i, n) {
            auto it = lower_bound(a.begin(), a.end(), i + 1);
            if (it == a.end() || *it != i + 1) amari.push(i + 1);
            else togo.push(i + 1);
        }
        rep(i,n){
            if(!togo.empty()){
                if(togo.front()!=c[i].first){
                    ans[togo.front()-1][i]=c[i].first;
                    togo.pop();
                }
                else{
                    togo.push(togo.front());
                    togo.pop();
                    if(togo.front()!=c[i].first){
                        ans[togo.front()-1][i]=c[i].first;
                        togo.pop();
                    }
                    else{
                        ans[amari.front()-1][i]=c[i].first;
                        amari.pop();
                    }
                }
            }
            else{
                ans[amari.front()-1][i]=c[i].first;
                amari.pop();
            }
        }
        rep(i,n) rep(j,n) if(ans[i][j]==-1) ans[i][j]=i+1;
        vector<vector<ll>> p(n,vector<ll>(n));
        rep(i,n) rep(j,n) p[r[i].second][c[j].second]=ans[i][j];
        rep(i,n) {
            rep(j,n) cout<<p[i][j]<<" ";
            cout<<endl;
        }
    }
}
0