結果

問題 No.5026 Spectrum Router
コンテスト
ユーザー ふらわぁ
提出日時 2026-11-23 21:59:26
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,863 ms / 2,000 ms
+ 706µs
コード長 5,153 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,394 ms
コンパイル使用メモリ 372,644 KB
実行使用メモリ 9,868 KB
スコア 824,541
最終ジャッジ日時 2026-11-23 22:01:33
合計ジャッジ時間 103,864 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//from https://yukicoder.me/users/24897/ai_code/29
#include <bits/stdc++.h>
using namespace std;
#ifdef _MSC_VER
#include <intrin.h>
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using P = pair<ll, ll>;
#define endl "\n"
#define rep1(i,n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,a,b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define rep(...) OVERLOAD_REP(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define rrep(i,n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
constexpr int MINT_MOD = 998244353;
const ll mod = MINT_MOD;
const ll inf = 4000000000000000000ll;
const ld eps = ld(0.00000000001);
static const long double pi = 3.141592653589793;
constexpr ll MAX = 2000010;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>auto min(const T& a){ return *min_element(all(a)); }
template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class U>bool chmax(T &a,const U b) { if (a<b) { a=b; return 1; } return 0;}
template<class T,class U>bool chmin(T &a,const U b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<V<V<T>>>;
template <class T>
auto mvec(T val, ll n) { return V<T>(n, val); }
template <class T, class... Args>
auto mvec(T val, ll n, Args... args) {
    return V<decltype(mvec(val, args...))>(n, mvec(val, args...));
}
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / i);}}}sort(all(ans)); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=gcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}
void cincout(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout<< fixed << setprecision(15);
}

struct Timer{//タイマーの本体 from https://atcoder.jp/contests/ahc073/submissions/80099112
    chrono::steady_clock::time_point st=chrono::steady_clock::now();
    double t(){
      auto diff=chrono::steady_clock::now()-st;
      chrono::duration<double> dbdiff=diff;
      return dbdiff.count();
    }
};

int main(){
  cincout();
  
  Timer timer;
  const double tl=1.9;
  
  ll n; cin>>n;
  auto a=mvec(0LL,4*n);
  rep(i,4*n){
    cin>>a[i]; a[i]--;
  }
  
  auto sc=mvec(0LL,n,n,3);
  rep(i,n){
    rep(j,n){
      sc[i][j][0]=abs(3*n-i-1-a[i])+abs(4*n-j-1-a[n+j])+abs(i-a[3*n-i-1])+abs(n+j-a[4*n-j-1]);
      sc[i][j][1]=abs(4*n-j-1-a[i])+abs(3*n-i-1-a[n+j])+abs(i-a[4*n-j-1])+abs(n+j-a[3*n-i-1]);
      sc[i][j][2]=abs(n+j-a[i])+abs(4*n-j-1-a[3*n-i-1])+abs(i-a[n+j])+abs(3*n-i-1-a[4*n-j-1]);
    }
  }
  ll sco=0;
  rep(i,n) rep(j,n) sco+=(i==j?sc[i][j][2]:sc[i][j][0]);
  
  P de; de.fi=0; de.se=0;
  auto bor=mvec(de,n);
  rep(i,n){
    bor[i].fi=i;
    if(sc[i][i][1]<sc[i][i][2]) bor[i].se=1;
    else bor[i].se=2;
  }
  
  while(1){
    ll le=rand()%n,ri=rand()%n;
    if(le==ri){
      continue;
    }
    else{
      ll les=0,res=0;
      if(sc[le][bor[ri].fi][1]<sc[le][bor[ri].fi][2]) les=1;
      else les=2;
      if(sc[ri][bor[le].fi][1]<sc[ri][bor[le].fi][2]) res=1;
      else res=2;
      if(sc[le][bor[ri].fi][les]+sc[ri][bor[le].fi][res]<=sc[le][bor[le].fi][bor[le].se]+sc[ri][bor[ri].fi][bor[ri].se]){
        swap(bor[le].fi,bor[ri].fi);
        bor[le].se=les; bor[ri].se=res;
      }
    }
    
    {//打ち切り
      double curt=timer.t();
      if(curt>tl) break;
    }
  }
  
  rep(i,n){
    rep(j,n){
      cout<<(j==bor[i].fi?bor[i].se:0);
    }
    cout<<"\n";
  }
  
  return 0;
}
0