結果

問題 No.5016 Worst Mayor
ユーザー KahukaKahuka
提出日時 2023-04-29 14:54:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 10,931 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 212,692 KB
実行使用メモリ 37,524 KB
スコア 0
最終ジャッジ日時 2023-04-29 14:54:33
合計ジャッジ時間 9,286 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define reps(i,s,n) for(int i=s; i<n; i++)
#define per(i,n) for(int i=n-1; i>=0; i--)
#define pers(i,n,s) for(int i=n-1; i>=s; i--)
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define lb(v,n) lower_bound(all(v),n)
#define lbi(v,n) int(lower_bound(all(v),n) - v.begin())
#define ub(v,n) upper_bound(all(v),n)
#define ubi(v,n) int(upper_bound(all(v),n) - v.begin())
 
#define mod 1000000007
#define infi 1010000000
#define infl 1100000000000000000
 
#define outve(v) {for(auto i : v) cout << i << " ";cout << endl;}
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define errve(v) {for(auto i : v) cout << i << " ";cout << endl;}
#define errmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];}
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int popcnt(uint n) {return __builtin_popcount(n);}
int popcntl(ull n) {return __builtin_popcountll(n);}
int bsr(uint n) {return 31 - __builtin_clz(n);}
int bsrl(ull n) {return 63 - __builtin_clzll(n);}
int bsf(uint n) {return __builtin_ctz(n);}
int bsfl(ull n) {return __builtin_ctzll(n);}


double TIME_LIMIT = 1.5;
int LOCAL = 0;
int TEATER = 0;

unsigned int xorshift() {
    static unsigned int tx = 123456789, ty=362436069, tz=521288629, tw=88675123;
    unsigned int tt = (tx^(tx<<11));
    tx = ty; ty = tz; tz = tw;
    return ( tw=(tw^(tw>>19))^(tt^(tt>>8)) );
}

class Timer {
    int ti;
    double time;
public:
    Timer(){}
    void start(){ti = clock();}
    inline double get_time(){return time = (LOCAL==1 ? 2.0 : 1.0) * (clock() - ti) / CLOCKS_PER_SEC;}
    inline double now(){return time;}
};






constexpr int dh[4] = {-1,0,1,0};
constexpr int dw[4] = {0,-1,0,1};
constexpr int N = 14;
constexpr int M = 30000;
constexpr int T = 400;


class SimulatedAnnealing {
    
    Timer timer;
    ll score;
    
    int home[M];
    int company[M];
    int D[196][196];
    int road[N][N];
    int road_num = 0;
    vi road_x;
    
    
    
    /*
    ll money_now = 1000000;
    ll people_now = 0;
    int R_now[N][N];
    pair<ll,ll> tester_in(){
        return make_pair(money_now,people_now);
    }
    void tester_out(int t, int h=-1, int w=-1, int k=-1){
        if(t == 3) money_now += 50000;
        else if(t == 2) people_now++;
        else {
            money_now -= 10000000ll/sqrt(people_now);
            ll d[196][196];
            int cn[196][196];
            rep(i,N) rep(j,N){
                int s = i*N+j;
                rep(h,N) rep(w,N) d[s][h*N+w] = infi;
                rep(h,N) rep(w,N) cn[s][h*N+w] = 0;
                d[s][s] = 0;
                pq1<ll> pq;
                pq.push(0*10000+i*100+j);
                while (!pq.empty()) {
                    ll chw = pq.top();
                    pq.pop();
                    ll c = chw/10000;
                    int h = (chw%10000)/100, w = chw%100;
                    if(d[s][h*N+w] < c) continue;
                    rep(k,4) {
                        int nh = h + dh[k], nw = w + dw[k];
                        if(nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
                        if(chmin(d[s][nh*N+nw], c+(road[h][w]&1<<k ? 223 : 10000))) {
                            pq.push((ll)d[s][nh*N+nw]*10000ll + nh*100 + nw);
                            cn[s][nh*N+nw] = cn[s][h*N+w]+(road[h][w]&1<<k ? 1 : 0);
                        }
                    }
                }
            }
            
            rep(i,M) res += 60ll*cn[home[i]][company[i]]*(T-road_num)/10;
            
        }
    }
    */
    
    
    
public:
    SimulatedAnnealing(){
        timer.start();
        
        int m,t;
        cin >> m >> t;
        rep(i,M) {
            int a,b,c,d;
            cin >> a >> b >> c >> d;
            a--,b--,c--,d--;
            home[i] = a*N+b;
            company[i] = c*N+d;
        }
        
        
        score = 0;
    }
    inline bool can_move(int h, int w, int k){
        int nh = h + dh[k], nw = w + dw[k];
        if(nh < 0 || nh >= N || nw < 0 || nw >= N) return false;
        return true;
    }
    
    ll cal_score(){
        ll res = -10000000LL*(ll)road_num;
        ll d[196][196];
        int cn[196][196];
        rep(i,N) rep(j,N){
            int s = i*N+j;
            rep(h,N) rep(w,N) d[s][h*N+w] = infi;
            rep(h,N) rep(w,N) cn[s][h*N+w] = 0;
            d[s][s] = 0;
            pq1<ll> pq;
            pq.push(0*10000+i*100+j);
            while (!pq.empty()) {
                ll chw = pq.top();
                pq.pop();
                ll c = chw/10000;
                int h = (chw%10000)/100, w = chw%100;
                if(d[s][h*N+w] < c) continue;
                rep(k,4) {
                    int nh = h + dh[k], nw = w + dw[k];
                    if(nh < 0 || nh >= N || nw < 0 || nw >= N) continue;
                    if(chmin(d[s][nh*N+nw], c+(road[h][w]&1<<k ? 223 : 10000))) {
                        pq.push((ll)d[s][nh*N+nw]*10000ll + nh*100 + nw);
                        cn[s][nh*N+nw] = cn[s][h*N+w]+(road[h][w]&1<<k ? 1 : 0);
                    }
                }
            }
        }
        
        rep(i,M) res += 60ll*cn[home[i]][company[i]]*(T-road_num)/10;
        
        return res;
    }
    
    
    void solve(){
        
        
        rep(i,N) rep(j,N) road[i][j] = 0;
        road_num = 5;
        rep(i,road_num) {
            int a = xorshift()%N;
            int b = xorshift()%N;
            int k = xorshift()%4;
            while ((road[a][b] & 1 << k) || !can_move(a,b,k)) {
                a = xorshift()%N, b = xorshift()%N, k = xorshift()%4;
            }
            road[a][b] |= 1<<k;
            road[a+dh[k]][b+dw[k]] |= 1<<((k+2)%4);
            road_x.pb(a*1000+b*10+k);
        }
        score = cal_score();
//        cerr << score << endl;
//
//        cerr << road_num << endl;
//        rep(i,N){
//            rep(j,N) cerr << bitset<4>(road[i][j]) << " ";
//            cerr << endl;
//        }
        
        int loop = 0;
        double T1 = 10, T0 = 0;
        double T = T1;
        while (timer.now() < TIME_LIMIT) {
            loop++;
            
            ll score0 = score;
            int road_num0 = road_num;
            int road0[N][N];
            vi road_x0 = road_x;
            rep(i,N) rep(j,N) road0[i][j] = road[i][j];
            
            int p = xorshift()%100;
            if(p <= 100){
                
                int n = xorshift()%road_num;
                int a = road_x[n]/1000, b = (road_x[n]%1000)/10, k = road_x[n]%10;
                road[a][b] &= ~(1<<k);
                road[a+dh[k]][b+dw[k]] &= ~(1<<((k+2)%4));
                a = xorshift()%N, b = xorshift()%N, k = xorshift()%4;
                while ((road[a][b] & 1 << k) || !can_move(a,b,k)) {a = xorshift()%N, b = xorshift()%N, k = xorshift()%4;}
                road[a][b] |= 1<<k;
                road[a+dh[k]][b+dw[k]] |= 1<<((k+2)%4);
                road_x[n] = (a*1000+b*10+k);
                
            }else if(p <= 80){
                
                int a = xorshift()%N, b = xorshift()%N, k = xorshift()%4;
                while ((road[a][b] & 1 << k) || !can_move(a,b,k)) {a = xorshift()%N, b = xorshift()%N, k = xorshift()%4;}
                road[a][b] |= 1<<k;
                road[a+dh[k]][b+dw[k]] |= 1<<((k+2)%4);
                road_x.pb(a*1000+b*10+k);
                road_num++;
                
            }else{
                int n = xorshift()%road_num;
                int a = road_x[n]/1000, b = (road_x[n]%1000)/10, k = road_x[n]%10;
                road[a][b] &= ~(1<<k);
                road[a+dh[k]][b+dw[k]] &= ~(1<<((k+2)%4));
                road_x.erase(road_x.begin()+n);
                road_num--;
            }
            
            
            
            
            ll score1 = cal_score();
            if(score0 < score1){
                score = score1;
                
            }else{
                if((double)(xorshift()%infi)/(double)infi < exp((score1-score0)/T)){
                    score = score1;
                    
                }else{
                    road_num = road_num0;
                    rep(i,N) rep(j,N) road[i][j] = road0[i][j];
                    road_x = road_x0;
                }
            }
            
            timer.get_time();
            T = T1 + (T0-T1)*timer.now()/TIME_LIMIT;
            if(LOCAL==1 && TEATER==0 && loop%100 == 0) cerr << loop csp score csp score0 csp road_num csp road_num0 csp timer.now() csp T << endl;
        }
        
        cerr << road_num << endl;
//        rep(i,N){
//            rep(j,N) cerr << bitset<4>(road[i][j]) << " ";
//            cerr << endl;
//        }
        cerr << score csp road_num csp timer.get_time() << endl;
        
        solve1();
    }
    
    
    void solve1(){
        
        ll money = 1000000, people = 0;
        int road_build = 0;
        rep(t,T){
            cin >> money >> people;
            if(road_build < road_num){
                if(people > 0 && money > (10000000ll/sqrt(people))){
                    int x = road_x[road_build]/1000, y = (road_x[road_build]%1000)/10, k = road_x[road_build]%10;
                    int z = x + dh[k], w = y+dw[k];
                    cout << 1 csp x+1 csp y+1 csp z+1 csp w+1 << endl;
                    road_build++;
                }else{
                    if(people < 30) {
                        cout << 2 << endl;
                    }else{
                        cout << 3 << endl;
                    }
                }
            }else{
                cout << 3 << endl;
            }
        }
        
    }
    
};


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


    SimulatedAnnealing solver;
    solver.solve();
    
    return 0;
}
0