結果

問題 No.5020 Averaging
ユーザー askr58askr58
提出日時 2024-02-25 15:52:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 411 ms / 1,000 ms
コード長 3,265 bytes
コンパイル時間 4,104 ms
コンパイル使用メモリ 284,220 KB
実行使用メモリ 19,844 KB
スコア 21,702,023
最終ジャッジ日時 2024-02-25 15:53:25
合計ジャッジ時間 25,860 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 402 ms
19,844 KB
testcase_01 AC 374 ms
19,844 KB
testcase_02 AC 375 ms
19,844 KB
testcase_03 AC 399 ms
19,844 KB
testcase_04 AC 371 ms
19,844 KB
testcase_05 AC 376 ms
19,844 KB
testcase_06 AC 404 ms
19,844 KB
testcase_07 AC 383 ms
19,844 KB
testcase_08 AC 383 ms
19,844 KB
testcase_09 AC 396 ms
19,844 KB
testcase_10 AC 378 ms
19,844 KB
testcase_11 AC 376 ms
19,844 KB
testcase_12 AC 379 ms
19,844 KB
testcase_13 AC 388 ms
19,844 KB
testcase_14 AC 381 ms
19,844 KB
testcase_15 AC 376 ms
19,844 KB
testcase_16 AC 390 ms
19,844 KB
testcase_17 AC 377 ms
19,844 KB
testcase_18 AC 383 ms
19,844 KB
testcase_19 AC 394 ms
19,844 KB
testcase_20 AC 384 ms
19,844 KB
testcase_21 AC 380 ms
19,844 KB
testcase_22 AC 387 ms
19,844 KB
testcase_23 AC 376 ms
19,844 KB
testcase_24 AC 376 ms
19,844 KB
testcase_25 AC 388 ms
19,844 KB
testcase_26 AC 377 ms
19,844 KB
testcase_27 AC 376 ms
19,844 KB
testcase_28 AC 392 ms
19,844 KB
testcase_29 AC 374 ms
19,844 KB
testcase_30 AC 411 ms
19,844 KB
testcase_31 AC 383 ms
19,844 KB
testcase_32 AC 388 ms
19,844 KB
testcase_33 AC 403 ms
19,844 KB
testcase_34 AC 379 ms
19,844 KB
testcase_35 AC 389 ms
19,844 KB
testcase_36 AC 375 ms
19,844 KB
testcase_37 AC 378 ms
19,844 KB
testcase_38 AC 388 ms
19,844 KB
testcase_39 AC 378 ms
19,844 KB
testcase_40 AC 385 ms
19,844 KB
testcase_41 AC 388 ms
19,844 KB
testcase_42 AC 377 ms
19,844 KB
testcase_43 AC 389 ms
19,844 KB
testcase_44 AC 373 ms
19,844 KB
testcase_45 AC 375 ms
19,844 KB
testcase_46 AC 385 ms
19,844 KB
testcase_47 AC 375 ms
19,844 KB
testcase_48 AC 407 ms
19,844 KB
testcase_49 AC 379 ms
19,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
struct card{
    ll a,b;
    card(){}
    card(ll a,ll b):a(a),b(b){}

    void print(){
        cout<<a<<" "<<b<<endl;
    }
};
bool operator<(card x,card y){
    if(x.a==y.a)return x.b<y.b;
    else return x.a<y.a;
}
card operator+(card x,card y){
    return card((x.a+y.a)/2,(x.b+y.b)/2);
}

const int m=6;
const vector<int> v={50,15,12,10,7,5,1};
const ll x=500000000000000000;
int n;
struct state{
    vector<int> chosenindex;
    double score;
    vector<card> c;
    vector<pair<int,int>> operations;

    void calc_score(){
        score=0;
        for(int i:chosenindex)score+=max(abs(c[i].a-x),abs(c[i].b-x));
    }

    state generate(set<int>& indexes){
        state res;
        res.chosenindex.resize(indexes.size());
        res.operations=operations;
        res.c=c;
        int t=0;
        for(int i:indexes){
            res.chosenindex[t]=chosenindex[i];
            t++;
        }
        for(int p:res.chosenindex){
            card t=res.c[p]+res.c[(p+1)%n];
            int index=(p+1)%n;
            for(int j=2;j<n;j++){
                card tt=res.c[p]+res.c[(p+j)%n];
                if(max(abs(t.a-x),abs(t.b-x))>max(abs(tt.a-x),abs(tt.b-x))){
                    index=(p+j)%n;
                    t=tt;
                }
            }

            res.c[p]=t;
            res.c[index]=t;
            res.operations.push_back(make_pair(p+1,index+1));


        }
        res.calc_score();
        return res;


    }
};
bool operator<(state p,state q){
    return p.score<q.score;
}
ll solver(int n,vector<card> c){
    auto f=[&](int p){
        card t=c[p]+c[(p+1)%n];
        int index=(p+1)%n;
        for(int j=2;j<n;j++){
            card tt=c[p]+c[(p+j)%n];
            if(max(abs(t.a-x),abs(t.b-x))>max(abs(tt.a-x),abs(tt.b-x))){
                index=(p+j)%n;
                t=tt;
            }
        }

        c[p]=t;
        c[index]=t;
        cout<<p+1;
        cout<<" ";
        cout<<index+1<<endl;

    };
    for(int i=0;i<m;i++){
        for(int j=0;j<v[i];j++){
            f(j);
        }
    }
    return max(abs(c[0].a-x),abs(c[0].b-x));



}
int main(){
    cin>>n;
    vector<card> c(n);
    random_device seed;
    mt19937 rnd(seed());
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        c[i]=card(a,b);
    }
    cout<<50<<endl;

    vector<state> beam(1);
    state c0;
    c0.c=c;
    c0.chosenindex.resize(n);
    for(int i=0;i<n;i++)c0.chosenindex[i]=i;
    beam[0]=c0;
    for(int i=0;i<m;i++){
        vector<state> new_beam(min((int)beam.size(),100)*100);
        for(int j=0;j<100;j++){
            set<int> indexes;
            for(int k=0;k<v[i+1];k++){
                int t=rnd()%v[i+1];
                while(indexes.count(t))t=rnd()%v[i+1];
                indexes.insert(t);
            }
            for(int k=0;k<min(100,(int)beam.size());k++){
                new_beam[k*100+j]=beam[k].generate(indexes);
            }
        }
        sort(new_beam.begin(),new_beam.end());
        new_beam.resize(100);
        beam=new_beam;
    }

    for(int i=0;i<50;i++){
        cout<<beam[0].operations[i].first;
        cout<<" ";
        cout<<beam[0].operations[i].second;
        cout<<endl;
    }





}
0