結果
問題 | No.5020 Averaging |
ユーザー | hirakuuuu |
提出日時 | 2024-02-25 16:59:08 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 994 ms / 1,000 ms |
コード長 | 5,264 bytes |
コンパイル時間 | 3,545 ms |
コンパイル使用メモリ | 268,140 KB |
実行使用メモリ | 6,676 KB |
スコア | 41,001,470 |
最終ジャッジ日時 | 2024-02-25 17:03:23 |
合計ジャッジ時間 | 55,749 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 992 ms
6,676 KB |
testcase_01 | AC | 991 ms
6,676 KB |
testcase_02 | AC | 992 ms
6,676 KB |
testcase_03 | AC | 992 ms
6,676 KB |
testcase_04 | AC | 991 ms
6,676 KB |
testcase_05 | AC | 992 ms
6,676 KB |
testcase_06 | AC | 991 ms
6,676 KB |
testcase_07 | AC | 992 ms
6,676 KB |
testcase_08 | AC | 991 ms
6,676 KB |
testcase_09 | AC | 991 ms
6,676 KB |
testcase_10 | AC | 992 ms
6,676 KB |
testcase_11 | AC | 991 ms
6,676 KB |
testcase_12 | AC | 992 ms
6,676 KB |
testcase_13 | AC | 991 ms
6,676 KB |
testcase_14 | AC | 991 ms
6,676 KB |
testcase_15 | AC | 992 ms
6,676 KB |
testcase_16 | AC | 990 ms
6,676 KB |
testcase_17 | AC | 992 ms
6,676 KB |
testcase_18 | AC | 992 ms
6,676 KB |
testcase_19 | AC | 991 ms
6,676 KB |
testcase_20 | AC | 991 ms
6,676 KB |
testcase_21 | AC | 991 ms
6,676 KB |
testcase_22 | AC | 991 ms
6,676 KB |
testcase_23 | AC | 991 ms
6,676 KB |
testcase_24 | AC | 992 ms
6,676 KB |
testcase_25 | AC | 992 ms
6,676 KB |
testcase_26 | AC | 990 ms
6,676 KB |
testcase_27 | AC | 991 ms
6,676 KB |
testcase_28 | AC | 994 ms
6,676 KB |
testcase_29 | AC | 991 ms
6,676 KB |
testcase_30 | AC | 991 ms
6,676 KB |
testcase_31 | AC | 991 ms
6,676 KB |
testcase_32 | AC | 991 ms
6,676 KB |
testcase_33 | AC | 992 ms
6,676 KB |
testcase_34 | AC | 991 ms
6,676 KB |
testcase_35 | AC | 991 ms
6,676 KB |
testcase_36 | AC | 992 ms
6,676 KB |
testcase_37 | AC | 990 ms
6,676 KB |
testcase_38 | AC | 991 ms
6,676 KB |
testcase_39 | AC | 992 ms
6,676 KB |
testcase_40 | AC | 991 ms
6,676 KB |
testcase_41 | AC | 991 ms
6,676 KB |
testcase_42 | AC | 991 ms
6,676 KB |
testcase_43 | AC | 991 ms
6,676 KB |
testcase_44 | AC | 991 ms
6,676 KB |
testcase_45 | AC | 992 ms
6,676 KB |
testcase_46 | AC | 991 ms
6,676 KB |
testcase_47 | AC | 991 ms
6,676 KB |
testcase_48 | AC | 991 ms
6,676 KB |
testcase_49 | AC | 991 ms
6,676 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i = a; i < n; i++) #define rrep(i, a, n) for(int i = a; i >= n; i--) #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> constexpr ll MOD = 1000000007; constexpr int IINF = 1001001001; constexpr ll INF = 1LL<<60; template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} // 問題 // https://yukicoder.me/problems/no/5020 const int TIME_LIMIT_1 = 490; const int TIME_LIMIT_2 = 990; constexpr ll base = 5e17; const double start_temp = 1000, end_temp = 1; int main(){ auto start_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count(); random_device seed_gen; mt19937 engine(seed_gen()); int n; cin >> n; vector<tuple<ll, ll, ll>> card(n), init(n); rep(i, 0, n){ ll a, b; cin >> a >> b; card[i] = {a, b, i}; init[i] = {a, b, i}; } sort(card.begin(), card.end()); vector<pair<ll, ll>> ope; rep(_, 0, 2){ rep(__, 0, 25){ // 1~25回目は表、26~50回目は裏が最大, 最小となるカードについて操作を行う auto [a, c, i] = card[0]; auto [b, d, j] = card[n-1]; card[0] = {(a+b)/2, (c+d)/2, i}; card[n-1] = {(a+b)/2, (c+d)/2, j}; ope.push_back({i, j}); sort(card.begin(), card.end()); } rep(i, 0, n){ auto [a, c, j] = card[i]; card[i] = {c, a, j}; } } // 1番のカード auto get_card1 = [&](vector<tuple<ll, ll, ll>> &card_) -> pair<ll, ll> { rep(i, 0, n){ auto [a, c, j] = card_[i]; if(!j){ return {a, c}; } } return {0, 0}; }; // スコア auto score = [&](pair<ll, ll> card_) -> ll { return (ll)(2e6-1e5*log10(max(abs(card_.first-base), abs(card_.second-base))+1)); }; // 操作 auto simulation = [&](vector<pair<ll, ll>> &ope_) -> ll { vector<tuple<ll, ll, ll>> card_ = init; for(auto [u, v]: ope_){ auto [a, c, i] = card_[u]; auto [b, d, j] = card_[v]; card_[u] = {(a+b)/2, (c+d)/2, i}; card_[v] = {(a+b)/2, (c+d)/2, j}; } return score(get_card1(card_)); }; ll best_score = simulation(ope), gati_best = best_score; constexpr int ope_size = 50; // 焼き鈍し int cnt = 0, tmp = 0; int f1 = 0, f2 = 0; while(true){ auto now_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count(); if(now_time-start_time >= TIME_LIMIT_1) break; vector<pair<ll, ll>> new_ope = ope; if(f1^f2){ int num = engine()%ope_size; int u = 0, v = engine()%(n-1)+1; new_ope[num] = {u, v}; }else if(f1&f2){ int num = engine()%ope_size; int u = engine()%(n-1)+1, v = engine()%(n-1)+1; while(u == v) v = engine()%(n-1)+1; new_ope[num] = {u, v}; }else{ int u = engine()%ope_size, v = engine()%ope_size; while(u == v) v = engine()%ope_size; swap(new_ope[u], new_ope[v]); } ll new_score = simulation(new_ope); chmax(gati_best, new_score); // 温度関数 double temp = start_temp+(end_temp-start_temp)*((double)(now_time-start_time))/(double)TIME_LIMIT_1; // 遷移確率関数(最大化の場合) double prob = min(1.0, exp((double)(new_score-best_score-1)/temp)); //if(cnt%100000 == 0) cout << new_score-best_score << ' ' << temp << ' ' << prob << endl; // 確率probで遷移する if (prob > (engine()%IINF)/(double)IINF) { tmp = cnt; swap(ope, new_ope); swap(best_score, new_score); } cnt++; f2 ^= f1; f1 ^= 1; } // 山登り while(true){ auto now_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count(); if(now_time-start_time >= TIME_LIMIT_2) break; vector<pair<ll, ll>> new_ope = ope; if(f1^f2){ int num = engine()%ope_size; int u = 0, v = engine()%(n-1)+1; new_ope[num] = {u, v}; }else if(f1&f2){ int num = engine()%ope_size; int u = engine()%(n-1)+1, v = engine()%(n-1)+1; while(u == v) v = engine()%(n-1)+1; new_ope[num] = {u, v}; }else{ int u = engine()%ope_size, v = engine()%ope_size; while(u == v) v = engine()%ope_size; swap(new_ope[u], new_ope[v]); } ll new_score = simulation(new_ope); if (new_score > best_score){ tmp = cnt; swap(ope, new_ope); swap(best_score, new_score); } cnt++; f2 ^= f1; f1 ^= 1; } //cout << simulation(ope) << ' ' << gati_best << ' ' << cnt << endl; // 出力 cout << ope.size() << endl; for(auto [u, v]: ope){ cout << u+1 << ' ' << v+1 << endl; } return 0; }