結果
問題 | No.5020 Averaging |
ユーザー | gucci0512 |
提出日時 | 2024-02-25 17:42:29 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 973 ms / 1,000 ms |
コード長 | 2,917 bytes |
コンパイル時間 | 4,050 ms |
コンパイル使用メモリ | 234,416 KB |
実行使用メモリ | 6,676 KB |
スコア | 82,088,483 |
最終ジャッジ日時 | 2024-02-25 17:43:23 |
合計ジャッジ時間 | 54,186 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 950 ms
6,676 KB |
testcase_01 | AC | 925 ms
6,676 KB |
testcase_02 | AC | 927 ms
6,676 KB |
testcase_03 | AC | 973 ms
6,676 KB |
testcase_04 | AC | 950 ms
6,676 KB |
testcase_05 | AC | 926 ms
6,676 KB |
testcase_06 | AC | 926 ms
6,676 KB |
testcase_07 | AC | 950 ms
6,676 KB |
testcase_08 | AC | 949 ms
6,676 KB |
testcase_09 | AC | 949 ms
6,676 KB |
testcase_10 | AC | 927 ms
6,676 KB |
testcase_11 | AC | 926 ms
6,676 KB |
testcase_12 | AC | 949 ms
6,676 KB |
testcase_13 | AC | 950 ms
6,676 KB |
testcase_14 | AC | 949 ms
6,676 KB |
testcase_15 | AC | 926 ms
6,676 KB |
testcase_16 | AC | 926 ms
6,676 KB |
testcase_17 | AC | 949 ms
6,676 KB |
testcase_18 | AC | 950 ms
6,676 KB |
testcase_19 | AC | 938 ms
6,676 KB |
testcase_20 | AC | 926 ms
6,676 KB |
testcase_21 | AC | 928 ms
6,676 KB |
testcase_22 | AC | 949 ms
6,676 KB |
testcase_23 | AC | 950 ms
6,676 KB |
testcase_24 | AC | 925 ms
6,676 KB |
testcase_25 | AC | 934 ms
6,676 KB |
testcase_26 | AC | 950 ms
6,676 KB |
testcase_27 | AC | 950 ms
6,676 KB |
testcase_28 | AC | 950 ms
6,676 KB |
testcase_29 | AC | 926 ms
6,676 KB |
testcase_30 | AC | 926 ms
6,676 KB |
testcase_31 | AC | 950 ms
6,676 KB |
testcase_32 | AC | 948 ms
6,676 KB |
testcase_33 | AC | 950 ms
6,676 KB |
testcase_34 | AC | 927 ms
6,676 KB |
testcase_35 | AC | 925 ms
6,676 KB |
testcase_36 | AC | 948 ms
6,676 KB |
testcase_37 | AC | 950 ms
6,676 KB |
testcase_38 | AC | 926 ms
6,676 KB |
testcase_39 | AC | 929 ms
6,676 KB |
testcase_40 | AC | 952 ms
6,676 KB |
testcase_41 | AC | 950 ms
6,676 KB |
testcase_42 | AC | 950 ms
6,676 KB |
testcase_43 | AC | 925 ms
6,676 KB |
testcase_44 | AC | 929 ms
6,676 KB |
testcase_45 | AC | 950 ms
6,676 KB |
testcase_46 | AC | 950 ms
6,676 KB |
testcase_47 | AC | 950 ms
6,676 KB |
testcase_48 | AC | 926 ms
6,676 KB |
testcase_49 | AC | 926 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 double TIME_LIMIT = 0.92; const ll BASE = 500000000000000000; lld Randomlld(){ lld res=0.0; lld tmp=1.0; rep(i,0,3){ tmp/=1024.0; res+=tmp*(lld)(random()%1024); } return res; } clock_t start=clock(); clock_t process=clock(); // random_device seed_gen; // mt19937 engine(seed_gen()); mt19937 engine(0); 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]); } ll CalcScore(){ P score=Simulate(); return max(abs(BASE-score.first),abs(BASE-score.second)); } void Output(){ cout << X << endl; rep(i,0,X)cout << u[i]+1 << " " << v[i]+1 << endl; } }; Solution InitSolve(){ Solution res_sol; rep(i,1,N){ res_sol.u.pb(0); res_sol.v.pb(i); res_sol.X++; } shuffle(all(res_sol.v),engine); return res_sol; } Solution Suggest(Solution &sol){ Solution next_sol=sol; int idx1=random()%sol.X; int idx2=random()%sol.X; while(idx1==idx2){ idx2=random()%sol.X; } swap(next_sol.u[idx1],next_sol.u[idx2]); swap(next_sol.v[idx1],next_sol.v[idx2]); return next_sol; } Solution HillClimbing(Solution sol){ Solution now_sol=sol; ll now_score=now_sol.CalcScore(); Solution best_sol=now_sol; ll best_score=now_score; while((double)(clock()-start)/CLOCKS_PER_SEC<TIME_LIMIT){ Solution next_sol=Suggest(now_sol); ll next_score=next_sol.CalcScore(); lld diff = log10((lld)now_score)-log10((lld)next_score); if(Randomlld()<exp(diff/0.2)){ if(chmin(best_score,next_score)){ best_sol=next_sol; } now_score=next_score; now_sol=next_sol; } } return best_sol; } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); Input(); Solution sol=InitSolve(); Solution next_sol=HillClimbing(sol); next_sol.Output(); ll score=next_sol.CalcScore(); cerr << score << endl; // sol.Output(); }