#include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define print(var) std::cout<<#var<<"="<<(var)< #define vvi vector #define vvvi vector #define ll long long #define vll vector #define vvll vector #define vvvll vector #define vmi vector #define vvmi vector #define vvvmi vector #define vs vector #define pii pair #define vpii vector #define vvpii vector #define bit(x,i)(((x)>>(i))&1) #define inf (1<<30) #define INF (1ll<<60) template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } template T nibutan(T ok, T ng, const F &f){while(abs(ok-ng)>1){T mid = (ok+ng)/2;(f(mid)?ok:ng) = mid;}return ok;} template vector digit(T x){vector res; while(x>0){res.push_back(x%10); x/=10;} return res;} #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(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> a[i] >> b[i]; } } }; struct State{ int n; unordered_set used; vi seq; pair now; State(IO& io) : n(io.n){ } void add_back(int i, IO& io){ if(used.find(i) != used.end()){ cerr << "error : " << i << " is already used" << endl; return; } now.first = (now.first + io.a[i])/2; now.second = (now.second + io.b[i])/2; seq.push_back(i); used.insert(i); } void swap(int i, int j, IO& io){ if(i>=seq.size()){ cerr << "seq size is " << seq.size() << " but i is " << i << endl; return; } if(used.find(j) != used.end()){ cerr << "error : " << j << " is already used" << endl; return; } now.first = now.first - io.a[seq[i]]*pow(0.5,seq.size()-i-1); now.second = now.second - io.b[seq[i]]*pow(0.5,seq.size()-i-1); seq[i] = j; now.first = now.first + io.a[j]*pow(0.5,seq.size()-i-1); now.second = now.second + io.b[j]*pow(0.5,seq.size()-i-1); seq[i] = j; used.insert(j); used.erase(seq[i]); } double get_score(){ double diff1 = now.first - 500000000000000000ll; double diff2 = now.second - 500000000000000000ll; double score = diff1*diff1 + diff2*diff2; return score; } void update(IO& io){ int coin = randrange(10); if(coin < 2 && seq.size() < n-1){ int i; do{ i = randrange(n-1)+1; }while(used.find(i) != used.end()); add_back(i,io); } else{ int i,j; i = randrange(seq.size()); do{ j = randrange(n-1)+1; }while(used.find(j) != used.end()); swap(i,j,io); } } }; 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(); while(get_time() - start_time < 900){ State state = now_state; state.update(io); if(chmin(now_score, state.get_score())){ swap(now_state, state); cout << now_score << endl; } } }