結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-25 13:32:03 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,740 bytes |
| コンパイル時間 | 4,778 ms |
| コンパイル使用メモリ | 264,580 KB |
| 実行使用メモリ | 6,548 KB |
| スコア | 12,719,802 |
| 最終ジャッジ日時 | 2024-02-25 13:32:23 |
| 合計ジャッジ時間 | 12,001 ms |
|
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 50 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=b-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double lld;
using namespace std;
using namespace atcoder;
const double TIME_LIMIT = 0.95;
const ll BASE = 500000000000000000;
clock_t start=clock();
clock_t process=clock();
// random_device seed_gen;
// mt19937 engine(seed_gen());
mt19937 engine(0);
typedef pair<ll,ll> P;
const int N = 45;
const int M = 50;
ll A[N],B[N];
void Input(){
int _n;cin >> _n;
rep(i,0,N)cin >> A[i] >> B[i];
}
struct Solution{
int X;
vector<int> u,v;
P Simulate(){
ll a[N],b[N];rep(i,0,N)a[i]=A[i],b[i]=B[i];
rep(i,0,X){
ll tmp1=(a[u[i]]+a[v[i]])/2;
ll tmp2=(b[u[i]]+b[v[i]])/2;
a[u[i]]=tmp1;a[v[i]]=tmp1;
b[u[i]]=tmp2;b[v[i]]=tmp2;
}
return P(a[0],b[0]);
}
void Output(){
cout << X << endl;
rep(i,0,X)cout << u[i]+1 << " " << v[i]+1 << endl;
}
};
Solution InitSolve(){
Solution res_sol;
rep(i,0,M){
while(true){
int x=random()%N;
int y=random()%N;
if(x==y)continue;
res_sol.u.pb(x);
res_sol.v.pb(y);
res_sol.X++;
break;
}
}
return res_sol;
}
Solution HillClimbing(Solution sol){
Solution now_sol=sol;
P now_score=now_sol.Simulate();
ll now_v1=abs(BASE-now_score.first);
ll now_v2=abs(BASE-now_score.second);
while((double)(clock()-start)/CLOCKS_PER_SEC<TIME_LIMIT){
int idx=random()%M;
int x=random()%N;
int y=random()%N;
while(x==y){
y=random()%N;
}
int pre_x=now_sol.u[idx];
int pre_y=now_sol.v[idx];
now_sol.u[idx]=x;
now_sol.v[idx]=y;
P next_score=now_sol.Simulate();
ll next_v1=abs(BASE-next_score.first);
ll next_v2=abs(BASE-next_score.second);
if(max(now_v1,now_v2)>max(next_v1,next_v2)){
now_v1=next_v1;
now_v2=next_v2;
now_score=next_score;
}
else{
now_sol.u[idx]=pre_x;
now_sol.v[idx]=pre_y;
}
}
return now_sol;
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
Input();
Solution sol=InitSolve();
P res=sol.Simulate();
sol=HillClimbing(sol);
cerr << res.first << " " << res.second << endl;
sol.Output();
}