結果

問題 No.5020 Averaging
ユーザー FplusFplusFFplusFplusF
提出日時 2024-02-25 13:51:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 953 ms / 1,000 ms
コード長 2,443 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 258,312 KB
実行使用メモリ 6,676 KB
スコア 41,701,548
最終ジャッジ日時 2024-02-25 13:52:32
合計ジャッジ時間 53,859 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using tii=tuple<int,int,int>;
using qii=tuple<int,int,int,int>;
using ll=long long;
using ld=long double;
const ll INF=1ll<<60;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> inline bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
auto program_start=chrono::system_clock::now();
mt19937 mt;
int rand_int(int r){    //[0,r)
    return mt()%r;
}
int rand_int(int l,int r){  //[l,r)
    return l+mt()%(r-l);
}
double rand_double(){   //[0.0,1.0]
    return (double)mt()/(double)mt19937::max();
}
const ll C=5e17;
int N;
vector<ll> A,B;
namespace Solver{
    int score(vector<pii> &ans){
        vector<ll> a=A,b=B;
        for(auto [u,v]:ans){
            a[v]=a[u]=(a[u]+a[v])/2;
            b[v]=b[u]=(b[u]+b[v])/2;
        }
        return floorl(2000000.0-100000.0*log10l(max(abs(C-a[0]),abs(C-b[0]))+1));
    }
    void solve(){
        vector<pii> ans;
        int pre_score=score(ans);
        while(true){
            auto now=chrono::system_clock::now();
            int ms=chrono::duration_cast<chrono::milliseconds>(now-program_start).count();
            if(950<=ms) break;
            vector<pii> new_ans=ans;
            int r=mt()%3;
            int x=rand_int(N),y=rand_int(N);
            if(x==y) continue;
            if(y<x) swap(x,y);
            if((int)new_ans.size()!=50&&r==0){
                int d=rand_int((int)new_ans.size()+1);
                new_ans.insert(new_ans.begin()+d,{x,y});
            }else if(!new_ans.empty()&&r==1){
                int d=rand_int((int)new_ans.size());
                new_ans.erase(new_ans.begin()+d);
            }else if(!new_ans.empty()){
                int d=rand_int((int)new_ans.size());
                new_ans[d]={x,y};
            }
            int new_score=score(new_ans);
            if(pre_score<=new_score){
                pre_score=new_score;
                ans=new_ans;
            }
        }
        cout << (int)ans.size() << '\n';
        for(auto [u,v]:ans) cout << u+1 << ' ' << v+1 << '\n';
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    A.resize(N);
    B.resize(N);
    rep(i,N) cin >> A[i] >> B[i];
    Solver::solve();
}
0