結果

問題 No.5026 Spectrum Router
コンテスト
ユーザー FplusFplusF
提出日時 2026-11-23 21:36:19
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,916 ms / 2,000 ms
+ 505µs
コード長 7,137 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,549 ms
コンパイル使用メモリ 344,556 KB
実行使用メモリ 9,868 KB
スコア 1,266,183
最終ジャッジ日時 2026-11-23 21:38:04
合計ジャッジ時間 104,835 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge5_0
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//ライブラリへのリンク
//https://drive.google.com/drive/folders/1QDp2j94gwNBUf6lF2M-FTs9NVAKFpw5R

#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using tii=tuple<int,int,int>;
using qii=tuple<int,int,int,int>;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
constexpr int INF=1e9;
constexpr ll INF_ll=1e18;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define replr(i,l,r) for (int i=(int)(l);i<(int)(r);i++)
#define all(v) v.begin(),v.end()
#define len(v) ((int)v.size())
template<class T> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin_ref(T &a,const T &b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax_ref(T &a,const T &b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

namespace Timer{
    chrono::steady_clock::time_point program_start,start;
    void program_start_snap(){
        program_start=start=chrono::steady_clock::now();
    }
    void snap(){
        start=chrono::steady_clock::now();
    }
    int get_ms(){
        auto now=chrono::steady_clock::now();
        int ms=chrono::duration_cast<chrono::milliseconds>(now-start).count();
        return ms;
    }
    int get_ms_all_program(){
        auto now=chrono::steady_clock::now();
        int ms=chrono::duration_cast<chrono::milliseconds>(now-program_start).count();
        return ms;
    }
}

mt19937 mt;
uint32_t rand_int(uint32_t r){  //[0,r)
    assert(r!=0);
    return ((uint64_t)mt()*r)>>32;
}
int rand_int(int l,int r){  //[l,r)
    assert(l<r);
    return l+rand_int(r-l);
}
constexpr double one_div_mt_max=1.0/(double)mt19937::max();
double rand_double(){  //[0.0,1.0]
    return mt()*one_div_mt_max;
}
double rand_double(double l,double r){  //[l,r]
    return l+rand_double()*(r-l);
}
template<class T> T get_random_element(const vector<T> &v){
    assert(!v.empty());
    return v[rand_int(len(v))];
}

template<class T> void add(vector<T> &a,vector<T> b){
    for(auto i:b) a.push_back(i);
}


template<class SA_State> SA_State SA(const SA_State &first_state,int limit_ms,double start_temp,double end_temp=0.0){

    SA_State state=first_state,best_state=state;
    

    
    int loop_cnt=0,accept_cnt=0;
    
    int ms=0;
    
    double temp=start_temp;
    
    Timer::snap();
    
    constexpr int b=16,sz=1<<b;
    
    array<double,sz> log_rd;
    
    rep(i,sz) log_rd[i]=log(rand_double());
    
    while(true){

        if((loop_cnt&1023)==1023){
            
            ms=Timer::get_ms();
            
            if(limit_ms<=ms) break;
            
            //temp=start_temp-(start_temp-end_temp)/limit_ms*ms;
            
            double t=(double)ms/limit_ms;
            temp=pow(start_temp,1-t)*pow(end_temp,t);
        }
        
        loop_cnt++;
        
        double accept_diff=log_rd[loop_cnt&(sz-1)]*temp;
        

        bool accepted=state.modify(accept_diff);
        
        if(accepted){
            
            accept_cnt++;
        
            if(best_state.score<state.score){
                best_state=state;
                cerr << "score:" << best_state.score << " ms:" << ms << " loop_cnt:" << loop_cnt << " accept_cnt:" << accept_cnt << endl;
            }
        }

    }

    
    cerr << "[result] " << "score:" << best_state.score << " ms:" << ms << " loop_cnt:" << loop_cnt << " accept_cnt:" << accept_cnt << endl;

    return best_state;
};

constexpr int N=64,M=N*4;

array<int,M> A;

array<array<int,4>,N*N> G;

int one(int i,int j){
    return i*N+j;
}
pii two(int x){
    return {x/N,x%N};
}


namespace Solver{
    
    struct State{
        
        array<int,N*N> mirror;
        
        int score=0;
        
        State(){
            mirror.fill(0);
            score=calc_score();
        }
        int calc_score(){
            array<int,M> b;
            b.fill(-1);
            
            rep(t,M){
                int d=0,p=0;
                if(t<N){
                    d=1;
                    p=one(0,t);
                }else if(t<N*2){
                    d=2;
                    p=one(t-N,N-1);
                }else if(t<N*3){
                    d=0;
                    p=one(N-1,N-1-(t-N*2));
                }else{
                    d=3;
                    p=one(N-1-(t-N*3),0);
                }
                
                while(true){
                    
                    if(mirror[p]==0){
                        
                    }else if(mirror[p]==1){
                        d=3-d;
                    }else if(mirror[p]==2){
                        d=(d+2)%4;
                    }else{
                        assert(0);
                    }
                    int np=G[p][d];
                    
                    if(np==-1){
                        break;
                    }
                    p=np;
                }
                
                auto [pi,pj]=two(p);
                
                if(d==0){
                    b[pj]=A[t];
                }else if(d==3){
                    b[N+pi]=A[t];
                }else if(d==1){
                    b[2*N+N-1-pj]=A[t];
                }else if(d==2){
                    b[3*N+N-1-pi]=A[t];
                }else{
                    assert(0);
                }
                
            }
            
            //TODO?
            
            int cnt=0;
            
            rep(i,M){
                replr(j,i+1,M){
                    if(b[j]<b[i]) cnt++;
                }
            }
            
            
            return M*(M-1)/2-cnt;
        }
        
        bool modify(double accept_diff){
            int p=rand_int(N*N),k=rand_int(1,3);
            
            int m=mirror[p];
            
            mirror[p]=(mirror[p]+k)%3;
            
            int new_score=calc_score();
            
            if(accept_diff<new_score-score){
                score=new_score;
                return true;
            }else{
                mirror[p]=m;
                return false;
            }
        }
        
    };
    
    
    void solve(){
        
        
        State state;
        
        state=SA(state,1900,100);
        
        rep(i,N){
            rep(j,N){
                cout << state.mirror[one(i,j)];
            }
            cout << '\n';
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Timer::program_start_snap();
    
    int n;
    cin >> n;
    
    rep(i,M){
        cin >> A[i];
        A[i]--;
    }
    
    rep(i,N*N) G[i].fill(-1);
    
    rep(i,N){
        rep(j,N){
            if(j+1<N){
                G[one(i,j)][3]=one(i,j+1);
                G[one(i,j+1)][2]=one(i,j);
            }
            if(i+1<N){
                G[one(i,j)][1]=one(i+1,j);
                G[one(i+1,j)][0]=one(i,j);
            }
        }
    }


    Solver::solve();
    exit(0);
}
0