結果

問題 No.5020 Averaging
ユーザー ぴぃいいいいぴぃいいいい
提出日時 2024-02-25 15:46:26
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,040 bytes
コンパイル時間 6,126 ms
コンパイル使用メモリ 320,568 KB
実行使用メモリ 6,676 KB
スコア 0
最終ジャッジ日時 2024-02-25 15:47:20
合計ジャッジ時間 53,526 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    unordered_set<int> used;
    vi seq;
    State(IO& io) : n(io.n){
    }

    void add(int i, int j, IO& io){
        if(i > seq.size()){
            cerr << "error : " << i << " is out of range" << endl;
            return;
        }
        if(used.find(j) != used.end()){
            cerr << "error : " << j << " is already used" << endl;
            return;
        }
        if(i == seq.size()) seq.push_back(j);
        else seq.insert(seq.begin()+i, j);
    }

    void swap(int i, int j, IO& io){
        if(i>=seq.size()){
            cerr << "seq size is " << seq.size() << " but i is " << i << endl;
            return;
        }
        if(used.find(j) != used.end()){
            cerr << "error : " << j << " is already used" << endl;
            return;
        }

        used.erase(seq[i]);
        seq[i] = j;
        used.insert(j);
    }

    void del(int i, IO& io){
        if(i>=seq.size()){
            cerr << "seq size is " << seq.size() << " but i is " << i << endl;
            return;
        }

        used.erase(seq[i]);
        seq.erase(seq.begin()+i);
    }
    
    void update(IO& io){
            int coin = randrange(10);
            if(seq.size()==0 || (coin < 3 && seq.size() < n-1)){
                int i = randrange(seq.size()+1);
                int j;
                do{
                    j = randrange(n-1)+1;
                }while(used.find(j) != used.end());
                
                add(i,j,io);
            }
            else if(coin < 6 && seq.size() > 0){
                int i = randrange(seq.size());
                del(i,io);
            }
            else{
                int i,j;
                i = randrange(seq.size());
                do{
                    j = randrange(n-1)+1;
                }while(used.find(j) != used.end());

                swap(i,j,io);
            }
        }
    
    double get_score(IO& io){
        double a = io.a[0];
        double b = io.b[0];
        for(int i=0;i<seq.size();i++){
            a += io.a[seq[i]];
            b += io.b[seq[i]];
            a/=2;
            b/=2;
        }
        double diff_a = a-5e17;
        double diff_b = b-5e17;
        return diff_a*diff_a + diff_b*diff_b;
    }

    void get_card(IO & io){
        double a = io.a[0];
        double b = io.b[0];
        for(int i=0;i<seq.size();i++){
            a += io.a[seq[i]];
            b += io.b[seq[i]];
            a/=2;
            b/=2;
        }
        cout << a << " " << b << 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);
    while(get_time() - start_time < 900){
        State state = now_state;
        state.update(io);
        if(chmin(now_score, state.get_score(io))){
            swap(now_state, state);
            #ifdef LOCAL
            cerr << now_score << endl;
            #endif
        }
    }
    
    vi ans = now_state.seq;
    cout << ans.size() << endl;
    for(auto e:ans){
        cout << 0 << " " << e << endl;
    }
}
0