結果

問題 No.5020 Averaging
ユーザー ぴぃいいいいぴぃいいいい
提出日時 2024-02-27 01:39:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 992 ms / 1,000 ms
コード長 3,951 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 132,340 KB
実行使用メモリ 6,676 KB
スコア 21,565,151
最終ジャッジ日時 2024-02-27 01:40:32
合計ジャッジ時間 53,791 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdint>
#include <algorithm>
#include <vector>
#include <iostream>
#include <chrono>
#include <math.h>
#include <climits>
using namespace std;

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define vvvll vector<vvll>
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

#ifdef LOCAL
#include "../../cpp-dump/dump.hpp"
#else
#define cpp_dump
#endif

static uint32_t xor128(void){
    static uint32_t x=123456789,y=362436069,z=521288629,w=88675123;
    uint32_t t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int randrange(int a){return (uint64_t(xor128()) * a >> 32); }
double randDouble(double a,double b){return a+(b-a)*xor128()/(double)ULONG_MAX;}

inline double get_time() {
    using namespace std::chrono;
    return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
}
double start_time = get_time();

struct IO{
    int n;
    vll a,b;
    IO(){}
    void input(){
        cin >> n;
        a.resize(n);
        b.resize(n);
        for(int i=0;i<n;i++){
            cin >> a[i] >> b[i];
        }
    }
};

struct State{
    IO *io;
    int n;
    vector<pair<int,int>> seq;
    State(IO& _io) : io(&_io) ,n(_io.n) {}

    void add(int i, int j, int k){
        if(k > seq.size()){
            cerr << "error : " << i << " is out of range" << endl;
            return;
        }
        seq.insert(seq.begin()+k,{i,j});
    }

    void del(int i){
        if(i>=seq.size()){
            cerr << "seq size is " << seq.size() << " but i is " << i << endl;
            return;
        }
        seq.erase(seq.begin()+i);
    }
    
    void update(){
            int coin = randrange(10);
            if(seq.size()==0 || (coin < 3 && seq.size() < 50)){
                int i = randrange(n);
                int j;
                do{ j = randrange(n); }while(i==j);
                int k = randrange(seq.size()+1);
                
                add(i,j,k);
            }
            else{
                int i = randrange(seq.size());
                del(i);
            }
        }
    
    double get_score(){
        vll a = io->a;
        vll b = io->b;
        for(int i=0;i<seq.size();i++){
            auto [x,y] = seq[i];
            ll ave_a = (a[x] + a[y])/2;
            ll ave_b = (b[x] + b[y])/2;
            a[x] = ave_a;
            b[x] = ave_b;
            a[y] = ave_a;
            b[y] = ave_b;
        }
        double diff_a = abs((double)a[0]-5e17);
        double diff_b = abs((double)b[0]-5e17);
        return max(diff_a,diff_b);
    }

    void get_card(){
        vll a = io->a;
        vll b = io->b;
        for(int i=0;i<seq.size();i++){
            auto [x,y] = seq[i];
            ll ave_a = (a[x] + a[y])/2ll;
            ll ave_b = (b[x] + b[y])/2ll;
            a[x] = ave_a;
            b[x] = ave_b;
            a[y] = ave_a;
            b[y] = ave_b;
        }
        cerr << a[0] << " " << b[0] << endl;
    }
};

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

    IO io;
    io.input();

    State now_state(io);
    double now_score = now_state.get_score();
    double TIME_LIMIT = 990;

    while(get_time() - start_time < TIME_LIMIT){
        State state = now_state;
        state.update();
        double score = state.get_score();
        double temp = now_score * 1e-1;
        double prob = exp((now_score - score) / temp);
        if(prob > randDouble(0,1)){
            swap(now_state, state);
            now_score = score;
            #ifdef LOCAL
            cerr << setprecision(15) << now_score << endl;
            #endif
        }
    }
    
    auto ans = now_state.seq;
    cout << ans.size() << endl;
    for(auto [x,y]:ans){
        cout << x+1 << " " << y+1 << endl;
    }

    #ifdef LOCAL
    now_state.get_card();
    #endif
}
0