結果
問題 | No.5020 Averaging |
ユーザー |
![]() |
提出日時 | 2024-02-27 01:39:38 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 992 ms / 1,000 ms |
コード長 | 3,951 bytes |
コンパイル時間 | 1,631 ms |
コンパイル使用メモリ | 132,340 KB |
実行使用メモリ | 6,676 KB |
スコア | 21,565,151 |
最終ジャッジ日時 | 2024-02-27 01:40:32 |
合計ジャッジ時間 | 53,791 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include <cstdint> #include <algorithm> #include <vector> #include <iostream> #include <chrono> #include <math.h> #include <climits> using namespace std; #define ll long long #define vll vector<ll> #define vvll vector<vll> #define vvvll vector<vvll> template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } #ifdef LOCAL #include "../../cpp-dump/dump.hpp" #else #define cpp_dump #endif static uint32_t xor128(void){ static uint32_t x=123456789,y=362436069,z=521288629,w=88675123; uint32_t t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } int randrange(int a){return (uint64_t(xor128()) * a >> 32); } double randDouble(double a,double b){return a+(b-a)*xor128()/(double)ULONG_MAX;} inline double get_time() { using namespace std::chrono; return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count(); } double start_time = get_time(); struct IO{ int n; vll a,b; IO(){} void input(){ cin >> n; a.resize(n); b.resize(n); for(int i=0;i<n;i++){ cin >> a[i] >> b[i]; } } }; struct State{ IO *io; int n; vector<pair<int,int>> seq; State(IO& _io) : io(&_io) ,n(_io.n) {} void add(int i, int j, int k){ if(k > seq.size()){ cerr << "error : " << i << " is out of range" << endl; return; } seq.insert(seq.begin()+k,{i,j}); } void del(int i){ if(i>=seq.size()){ cerr << "seq size is " << seq.size() << " but i is " << i << endl; return; } seq.erase(seq.begin()+i); } void update(){ int coin = randrange(10); if(seq.size()==0 || (coin < 3 && seq.size() < 50)){ int i = randrange(n); int j; do{ j = randrange(n); }while(i==j); int k = randrange(seq.size()+1); add(i,j,k); } else{ int i = randrange(seq.size()); del(i); } } double get_score(){ vll a = io->a; vll b = io->b; for(int i=0;i<seq.size();i++){ auto [x,y] = seq[i]; ll ave_a = (a[x] + a[y])/2; ll ave_b = (b[x] + b[y])/2; a[x] = ave_a; b[x] = ave_b; a[y] = ave_a; b[y] = ave_b; } double diff_a = abs((double)a[0]-5e17); double diff_b = abs((double)b[0]-5e17); return max(diff_a,diff_b); } void get_card(){ vll a = io->a; vll b = io->b; for(int i=0;i<seq.size();i++){ auto [x,y] = seq[i]; ll ave_a = (a[x] + a[y])/2ll; ll ave_b = (b[x] + b[y])/2ll; a[x] = ave_a; b[x] = ave_b; a[y] = ave_a; b[y] = ave_b; } cerr << a[0] << " " << b[0] << endl; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); IO io; io.input(); State now_state(io); double now_score = now_state.get_score(); double TIME_LIMIT = 990; while(get_time() - start_time < TIME_LIMIT){ State state = now_state; state.update(); double score = state.get_score(); double temp = now_score * 1e-1; double prob = exp((now_score - score) / temp); if(prob > randDouble(0,1)){ swap(now_state, state); now_score = score; #ifdef LOCAL cerr << setprecision(15) << now_score << endl; #endif } } auto ans = now_state.seq; cout << ans.size() << endl; for(auto [x,y]:ans){ cout << x+1 << " " << y+1 << endl; } #ifdef LOCAL now_state.get_card(); #endif }