結果

問題 No.5020 Averaging
ユーザー ぴぃいいいいぴぃいいいい
提出日時 2024-02-25 16:51:52
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 992 ms / 1,000 ms
コード長 4,763 bytes
コンパイル時間 5,550 ms
コンパイル使用メモリ 316,832 KB
実行使用メモリ 6,548 KB
スコア 31,179,799
最終ジャッジ日時 2024-02-25 16:53:34
合計ジャッジ時間 57,783 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define print(var) std::cout<<#var<<"="<<(var)<<std::endl
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vmi vector<mint>
#define vvmi vector<vmi>
#define vvvmi vector<vvmi>
#define vs vector<string>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define bit(x,i)(((x)>>(i))&1)
#define inf (1<<30)
#define INF (1ll<<60)
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)); }
template<class T, class F> T nibutan(T ok, T ng, const F &f){while(abs(ok-ng)>1){T mid = (ok+ng)/2;(f(mid)?ok:ng) = mid;}return ok;}
template<class T> vector<T> digit(T x){vector<T> res; while(x>0){res.push_back(x%10); x/=10;} return res;}

#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{
    int n;
    vector<pair<int,int>> seq;
    State(IO& io) : n(io.n){}

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

    void del(int i, const IO& io){
        if(i>=seq.size()){
            cerr << "seq size is " << seq.size() << " but i is " << i << endl;
            return;
        }
        seq.erase(seq.begin()+i);
    }
    
    void update(const IO& io){
            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,io);
            }
            else{
                int i = randrange(seq.size());
                del(i,io);
            }
        }
    
    double get_score(const IO& io){
        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(const IO & io){
        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(io);
    double TIME_LIMIT = 990;
    double t0 = 1e13;
    double t1 = 1;

    while(get_time() - start_time < TIME_LIMIT){
        State state = now_state;
        state.update(io);
        double score = state.get_score(io);
        double temp = t0 + (t1 - t0) * (get_time() - start_time) / TIME_LIMIT;
        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(io);
    #endif
}
0