結果
問題 | No.5020 Averaging |
ユーザー |
|
提出日時 | 2024-02-25 14:46:40 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,073 bytes |
コンパイル時間 | 3,229 ms |
コンパイル使用メモリ | 265,796 KB |
実行使用メモリ | 6,676 KB |
スコア | 0 |
最終ジャッジ日時 | 2024-02-25 14:47:34 |
合計ジャッジ時間 | 53,563 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 50 |
ソースコード
#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/5020const int TIME_LIMIT = 950;int main(){auto start_time = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();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, 20){// 1~20回目は表、20~40回目は裏が最大, 最小となるカードについて操作を行う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 {ll base = 5e17;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);ll ope_size = (ll)ope.size();// 山登り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) break;vector<pair<ll, ll>> new_ope = ope;int num = rand()%(ope_size);int u = rand()%n, v = rand()%n;while(u == v) v = rand()%n;new_ope[num] = {u, v};ll new_score = simulation(new_ope);if(best_score < new_score){swap(ope, new_ope);swap(best_score, new_score);}}// cout << simulation(ope) << endl;// 出力cout << ope.size() << endl;for(auto [u, v]: ope){cout << u << ' ' << v << endl;}return 0;}