結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-02-25 15:24:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 952 ms / 1,000 ms |
| コード長 | 4,504 bytes |
| コンパイル時間 | 3,543 ms |
| コンパイル使用メモリ | 268,216 KB |
| 実行使用メモリ | 6,548 KB |
| スコア | 51,553,507 |
| 最終ジャッジ日時 | 2024-02-25 15:25:52 |
| 合計ジャッジ時間 | 53,596 ms |
|
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using tii=tuple<int,int,int>;
using qii=tuple<int,int,int,int>;
using ll=long long;
using ld=long double;
const ll INF=1ll<<60;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> inline bool chmin(T &a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
auto program_start=chrono::system_clock::now();
mt19937 mt;
int rand_int(int r){ //[0,r)
return mt()%r;
}
int rand_int(int l,int r){ //[l,r)
return l+mt()%(r-l);
}
double rand_double(){ //[0.0,1.0]
return (double)mt()/(double)mt19937::max();
}
const ll C=5e17;
int N;
vector<ll> A,B;
namespace Solver{
ll fake_score(vector<int> &v){
__int128 a_sum=0,b_sum=0;
rep(i,N){
a_sum+=(__int128)A[i]*(1ll<<v[i]);
b_sum+=(__int128)B[i]*(1ll<<v[i]);
}
a_sum/=(1ll<<(N-1));
b_sum/=(1ll<<(N-1));
return floorl(2000000.0-100000.0*log10l(max(abs(C-(ll)a_sum),abs(C-(ll)b_sum))+1));
}
int score(vector<pii> &ans){
vector<ll> a=A,b=B;
for(auto [u,v]:ans){
a[v]=a[u]=(a[u]+a[v])/2;
b[v]=b[u]=(b[u]+b[v])/2;
}
return floorl(2000000.0-100000.0*log10l(max(abs(C-a[0]),abs(C-b[0]))+1));
}
void solve(){
vector<int> k;
rep(i,N-1){
k.push_back(i);
if(i==0) k.push_back(i);
}
int pre_fake_score=fake_score(k);
while(true){
auto now=chrono::system_clock::now();
int ms=chrono::duration_cast<chrono::milliseconds>(now-program_start).count();
if(50<=ms) break;
int x=rand_int(N),y=rand_int(N);
if(x==y) continue;
swap(k[x],k[y]);
int new_fake_score=fake_score(k);
if(new_fake_score<pre_fake_score) swap(k[x],k[y]);
else pre_fake_score=new_fake_score;
}
vector<int> ord(N);
rep(i,N) ord[i]=i;
sort(all(ord),[&](int i,int j){return k[i]<k[j];});
vector<pii> start_ans;
bool zero=false;
rep(i,N){
if(zero&&ord[i]==0) continue;
if(zero||i==N-1) start_ans.emplace_back(0,ord[i]);
else{
start_ans.emplace_back(ord[i],ord[i+1]);
if(ord[i+1]==0) zero=true;
}
}
vector<pii> ans=start_ans;
int pre_score=score(ans);
int cnt=0;
int max_score=0;
vector<pii> max_score_ans;
while(true){
auto now=chrono::system_clock::now();
int ms=chrono::duration_cast<chrono::milliseconds>(now-program_start).count();
if(950<=ms) break;
vector<pii> new_ans=ans;
int r=mt()%4;
int x=rand_int(N),y=rand_int(N);
int sz=new_ans.size();
if(x==y) continue;
if(y<x) swap(x,y);
if(sz==0||(sz<50&&r==0)){
int d=rand_int(sz+1);
new_ans.insert(new_ans.begin()+d,{x,y});
}else if(r==1){
int d=rand_int(sz);
new_ans.erase(new_ans.begin()+d);
}else if(r==2){
int p=rand_int(sz),q=rand_int(sz);
if(p==q) continue;
if(q<p) swap(p,q);
reverse(new_ans.begin()+p,new_ans.begin()+q+1);
}else{
int d=rand_int(sz);
new_ans[d]={x,y};
}
cnt++;
int new_score=score(new_ans);
if(pre_score<=new_score){
if(pre_score<new_score){
cnt=0;
if(chmax(max_score,new_score)){
max_score_ans=new_ans;
}
}
pre_score=new_score;
ans=new_ans;
}
if(cnt==100000){
ans=start_ans;
pre_score=score(ans);
cnt=0;
}
}
cerr << max_score << endl;
cout << (int)max_score_ans.size() << '\n';
for(auto [u,v]:max_score_ans) cout << u+1 << ' ' << v+1 << '\n';
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
A.resize(N);
B.resize(N);
rep(i,N) cin >> A[i] >> B[i];
Solver::solve();
}
FplusFplusF