結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
ぴぃいいいい
|
| 提出日時 | 2024-02-25 15:28:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,186 bytes |
| コンパイル時間 | 7,463 ms |
| コンパイル使用メモリ | 318,116 KB |
| 実行使用メモリ | 6,548 KB |
| スコア | 0 |
| 最終ジャッジ日時 | 2024-02-25 15:29:17 |
| 合計ジャッジ時間 | 54,665 ms |
|
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 50 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define print(var) std::cout<<#var<<"="<<(var)<<std::endl
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vmi vector<mint>
#define vvmi vector<vmi>
#define vvvmi vector<vvmi>
#define vs vector<string>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define bit(x,i)(((x)>>(i))&1)
#define inf (1<<30)
#define INF (1ll<<60)
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)); }
template<class T, class F> 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<class T> vector<T> digit(T x){vector<T> 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<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{
int n;
unordered_set<int> used;
vi seq;
pair<double,double> 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;
}
}
}
ぴぃいいいい