結果
問題 | No.5020 Averaging |
ユーザー | gucci0512 |
提出日時 | 2024-02-25 15:14:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 977 ms / 1,000 ms |
コード長 | 5,661 bytes |
コンパイル時間 | 4,498 ms |
コンパイル使用メモリ | 240,820 KB |
実行使用メモリ | 6,676 KB |
スコア | 34,592,550 |
最終ジャッジ日時 | 2024-02-25 15:15:41 |
合計ジャッジ時間 | 55,861 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge10 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 975 ms
6,548 KB |
testcase_01 | AC | 950 ms
6,548 KB |
testcase_02 | AC | 976 ms
6,548 KB |
testcase_03 | AC | 953 ms
6,548 KB |
testcase_04 | AC | 977 ms
6,548 KB |
testcase_05 | AC | 950 ms
6,548 KB |
testcase_06 | AC | 926 ms
6,548 KB |
testcase_07 | AC | 950 ms
6,548 KB |
testcase_08 | AC | 950 ms
6,548 KB |
testcase_09 | AC | 950 ms
6,548 KB |
testcase_10 | AC | 950 ms
6,548 KB |
testcase_11 | AC | 926 ms
6,548 KB |
testcase_12 | AC | 950 ms
6,548 KB |
testcase_13 | AC | 950 ms
6,548 KB |
testcase_14 | AC | 953 ms
6,548 KB |
testcase_15 | AC | 926 ms
6,548 KB |
testcase_16 | AC | 952 ms
6,548 KB |
testcase_17 | AC | 951 ms
6,548 KB |
testcase_18 | AC | 953 ms
6,548 KB |
testcase_19 | AC | 926 ms
6,548 KB |
testcase_20 | AC | 930 ms
6,548 KB |
testcase_21 | AC | 953 ms
6,548 KB |
testcase_22 | AC | 926 ms
6,548 KB |
testcase_23 | AC | 954 ms
6,548 KB |
testcase_24 | AC | 931 ms
6,548 KB |
testcase_25 | AC | 951 ms
6,548 KB |
testcase_26 | AC | 951 ms
6,548 KB |
testcase_27 | AC | 926 ms
6,548 KB |
testcase_28 | AC | 951 ms
6,548 KB |
testcase_29 | AC | 926 ms
6,548 KB |
testcase_30 | AC | 950 ms
6,548 KB |
testcase_31 | AC | 944 ms
6,548 KB |
testcase_32 | AC | 927 ms
6,548 KB |
testcase_33 | AC | 951 ms
6,548 KB |
testcase_34 | AC | 927 ms
6,548 KB |
testcase_35 | AC | 950 ms
6,548 KB |
testcase_36 | AC | 926 ms
6,548 KB |
testcase_37 | AC | 952 ms
6,548 KB |
testcase_38 | AC | 931 ms
6,548 KB |
testcase_39 | AC | 929 ms
6,548 KB |
testcase_40 | AC | 951 ms
6,548 KB |
testcase_41 | AC | 926 ms
6,548 KB |
testcase_42 | AC | 952 ms
6,548 KB |
testcase_43 | AC | 927 ms
6,548 KB |
testcase_44 | AC | 951 ms
6,548 KB |
testcase_45 | AC | 926 ms
6,548 KB |
testcase_46 | AC | 950 ms
6,548 KB |
testcase_47 | AC | 928 ms
6,548 KB |
testcase_48 | AC | 951 ms
6,548 KB |
testcase_49 | AC | 936 ms
6,676 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=b-1;i>=a;i--) #define all(x) (x).begin(),(x).end() #define pb(x) push_back(x); template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } typedef long long ll; typedef long double lld; using namespace std; using namespace atcoder; const ll INF = (1ll<<60); const double TIME_LIMIT = 0.92; const ll BASE = 500000000000000000; clock_t start=clock(); clock_t process=clock(); // random_device seed_gen; // mt19937 engine(seed_gen()); mt19937 engine(0); ll BigRandom(){ ll res=0; rep(dgt,0,60){ res*=2; res+=random()%2; } return res; } typedef pair<ll,ll> P; const int N = 45; const int M = 50; ll A[N],B[N]; void Input(){ int _n;cin >> _n; rep(i,0,N)cin >> A[i] >> B[i]; } struct Solution{ int X=0; vector<int> u,v; P Simulate(){ ll a[N],b[N];rep(i,0,N)a[i]=A[i],b[i]=B[i]; rep(i,0,X){ ll tmp1=(a[u[i]]+a[v[i]])/2; ll tmp2=(b[u[i]]+b[v[i]])/2; a[u[i]]=tmp1;a[v[i]]=tmp1; b[u[i]]=tmp2;b[v[i]]=tmp2; } return P(a[0],b[0]); } lld CalcScore(){ P res=Simulate(); ll max_v=max(abs(BASE-res.first),abs(BASE-res.second)); return log10(max_v); } void Output(){ cout << X << endl; rep(i,0,X)cout << u[i]+1 << " " << v[i]+1 << endl; } }; Solution InitSolve(){ Solution res_sol; set<int> st; st.insert(0); rep(i,0,M){ int x=random()%N; int y=random()%N; while(true){ if(x!=y&&(st.count(x)||st.count(y))){ break; } x=random()%N; y=random()%N; } res_sol.u.pb(x); res_sol.v.pb(y); res_sol.X++; st.insert(x); st.insert(y); } reverse(all(res_sol.u)); reverse(all(res_sol.v)); return res_sol; } Solution Suggest(Solution &sol){ Solution next_sol=sol; lld next_score=INF; int idx=random()%M; int pre_x=sol.u[idx]; int pre_y=sol.v[idx]; rep(x,0,N)rep(y,0,N){ if(x==y)continue; sol.u[idx]=x; sol.v[idx]=y; lld score=sol.CalcScore(); if(chmin(next_score,score)){ next_sol.u[idx]=x; next_sol.v[idx]=y; } } sol.u[idx]=pre_x; sol.v[idx]=pre_y; return next_sol; } Solution PartSuggest(Solution &sol){ Solution next_sol=sol; set<int> idxs; int swap_size=random()%5+1; while(idxs.size()<swap_size){ idxs.insert(random()%M); } vector<int> idxs_v;for(auto idx:idxs)idxs_v.pb(idx); sort(all(idxs_v));reverse(all(idxs_v)); for(auto idx:idxs_v){ int x=random()%N; int y=random()%N; while(true){ bool break_flag=true; if(x==y){ break_flag=false; } if(idx==M-1){ if(x!=0&&y!=0){ break_flag=false; } } if(break_flag){ break; } x=random()%N; y=random()%N; } next_sol.u[idx]=x; next_sol.v[idx]=y; } return next_sol; } Solution HillClimbing(Solution sol){ int cnt=0; Solution now_sol=sol; lld now_score=now_sol.CalcScore(); while((double)(clock()-start)/CLOCKS_PER_SEC<TIME_LIMIT){ // Solution next_sol=Suggest(now_sol); Solution next_sol=PartSuggest(now_sol); lld next_score=next_sol.CalcScore(); if(chmin(now_score,next_score)){ now_sol=next_sol; cerr << now_score << endl; } cnt++; } cerr << "cnt: " << cnt << endl; return now_sol; } Solution SimulatedAnnealing(Solution sol){ int cnt=0; Solution now_sol=sol; P now_score=now_sol.Simulate(); ll now_v1=abs(BASE-now_score.first); ll now_v2=abs(BASE-now_score.second); double start_temp = 20; double end_temp = 2; double temp = start_temp; while((double)(clock()-start)/CLOCKS_PER_SEC<TIME_LIMIT){ Solution next_sol=PartSuggest(now_sol); temp=start_temp+(end_temp-start_temp)*(clock()-start)/CLOCKS_PER_SEC/TIME_LIMIT; // if(max(now_v1,now_v2)>max(next_v1,next_v2)){ // now_v1=next_v1; // now_v2=next_v2; // now_sol.u[idx]=next_x; // now_sol.v[idx]=next_y; // } // else{ // lld log_now_score = log10(max(now_v1,now_v2)); // lld log_next_score = log10(max(next_v1,next_v2)); // double prob = exp((log_next_score-log_now_score)/temp); // if(prob>lld(BigRandom()%INF)/INF){ // now_v1=next_v1; // now_v2=next_v2; // now_sol.u[idx]=next_x; // now_sol.v[idx]=next_y; // } // } // cnt++; if(cnt%100==0)cerr << cnt << " " << temp << endl; } cerr << "cnt: " << cnt << endl; return now_sol; } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); Input(); Solution sol=InitSolve(); // P res=sol.Simulate(); Solution next_sol=HillClimbing(sol); // Solution next_sol=SimulatedAnnealing(sol); P next_score=next_sol.Simulate(); ll next_v1=abs(BASE-next_score.first); ll next_v2=abs(BASE-next_score.second); cerr << next_v1 << " " << next_v2 << endl; next_sol.Output(); // sol.Output(); return 0; }