結果

問題 No.5020 Averaging
ユーザー ぴぃいいいいぴぃいいいい
提出日時 2024-02-25 16:26:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 903 ms / 1,000 ms
コード長 4,967 bytes
コンパイル時間 8,093 ms
コンパイル使用メモリ 320,760 KB
実行使用メモリ 6,548 KB
スコア 20,851,077
最終ジャッジ日時 2024-02-25 16:27:56
合計ジャッジ時間 53,967 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 902 ms
6,548 KB
testcase_01 AC 900 ms
6,548 KB
testcase_02 AC 902 ms
6,548 KB
testcase_03 AC 902 ms
6,548 KB
testcase_04 AC 902 ms
6,548 KB
testcase_05 AC 902 ms
6,548 KB
testcase_06 AC 902 ms
6,548 KB
testcase_07 AC 902 ms
6,548 KB
testcase_08 AC 901 ms
6,548 KB
testcase_09 AC 902 ms
6,548 KB
testcase_10 AC 901 ms
6,548 KB
testcase_11 AC 901 ms
6,548 KB
testcase_12 AC 902 ms
6,548 KB
testcase_13 AC 902 ms
6,548 KB
testcase_14 AC 902 ms
6,548 KB
testcase_15 AC 901 ms
6,548 KB
testcase_16 AC 901 ms
6,548 KB
testcase_17 AC 901 ms
6,548 KB
testcase_18 AC 901 ms
6,548 KB
testcase_19 AC 902 ms
6,548 KB
testcase_20 AC 902 ms
6,548 KB
testcase_21 AC 902 ms
6,548 KB
testcase_22 AC 901 ms
6,548 KB
testcase_23 AC 902 ms
6,548 KB
testcase_24 AC 902 ms
6,548 KB
testcase_25 AC 902 ms
6,548 KB
testcase_26 AC 901 ms
6,548 KB
testcase_27 AC 902 ms
6,548 KB
testcase_28 AC 902 ms
6,548 KB
testcase_29 AC 901 ms
6,548 KB
testcase_30 AC 901 ms
6,548 KB
testcase_31 AC 900 ms
6,548 KB
testcase_32 AC 901 ms
6,548 KB
testcase_33 AC 902 ms
6,548 KB
testcase_34 AC 902 ms
6,548 KB
testcase_35 AC 902 ms
6,548 KB
testcase_36 AC 902 ms
6,548 KB
testcase_37 AC 902 ms
6,548 KB
testcase_38 AC 902 ms
6,548 KB
testcase_39 AC 903 ms
6,548 KB
testcase_40 AC 902 ms
6,548 KB
testcase_41 AC 902 ms
6,548 KB
testcase_42 AC 901 ms
6,548 KB
testcase_43 AC 901 ms
6,548 KB
testcase_44 AC 901 ms
6,548 KB
testcase_45 AC 901 ms
6,548 KB
testcase_46 AC 900 ms
6,548 KB
testcase_47 AC 902 ms
6,548 KB
testcase_48 AC 902 ms
6,548 KB
testcase_49 AC 902 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;
    unordered_set<int> used;
    vi seq;
    State(IO& io) : n(io.n){
        used.insert(0);
    }

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

    void swap(int i, int j, const IO& io){
        if(i>=seq.size()){
            cerr << "seq size is " << seq.size() << " but i is " << i << endl;
            return;
        }
        used.erase(seq[i]);
        seq[i] = j;
        used.insert(j);
    }

    void del(int i, const 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(const IO& io){
            int coin = randrange(10);
            if(seq.size()==0 || (coin < 3 && seq.size() < 50)){
                int i = randrange(seq.size()+1);
                int j = randrange(n-1)+1;
                
                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());
                j = randrange(n-1)+1;

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

    void get_card(const IO & io){
        vll a = io.a;
        vll b = io.b;
        for(int i=0;i<seq.size();i++){
            ll ave_a = (a[0] + io.a[seq[i]])/2;
            ll ave_b = (b[0] + io.b[seq[i]])/2;
            a[0] = ave_a;
            b[0] = ave_b;
            a[seq[i]] = ave_a;
            b[seq[i]] = 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);
    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 << setprecision(15) << now_score << endl;
            #endif
        }
    }
    
    vi ans = now_state.seq;
    cout << ans.size() << endl;
    for(auto e:ans){
        cout << 1 << " " << e+1 << endl;
    }

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