結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
fuppy_kyopro
|
| 提出日時 | 2024-02-25 15:35:08 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 983 ms / 1,000 ms |
| コード長 | 10,474 bytes |
| コンパイル時間 | 3,608 ms |
| コンパイル使用メモリ | 235,720 KB |
| 実行使用メモリ | 6,548 KB |
| スコア | 82,565,200 |
| 最終ジャッジ日時 | 2024-02-25 15:36:04 |
| 合計ジャッジ時間 | 55,697 ms |
|
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
//*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//*/
#include <bits/stdc++.h>
// #include <atcoder/all>
// #include <atcoder/lazysegtree>
using namespace std;
// using namespace atcoder;
// #define _GLIBCXX_DEBUG
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int iiiiiiii = 0; iiiiiiii < v.size(); iiiiiiii++) \
cerr << " " << v[iiiiiiii]; \
cerr << endl;
#define DEBUG_MAT(v) \
cerr << #v << endl; \
for (int iv = 0; iv < v.size(); iv++) { \
for (int jv = 0; jv < v[iv].size(); jv++) { \
cerr << v[iv][jv] << " "; \
} \
cerr << endl; \
}
typedef long long ll;
// #define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (int)(n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
void YES(bool t = true) {
cout << (t ? "YES" : "NO") << endl;
}
void Yes(bool t = true) { cout << (t ? "Yes" : "No") << endl; }
void yes(bool t = true) { cout << (t ? "yes" : "no") << endl; }
void NO(bool t = true) { cout << (t ? "NO" : "YES") << endl; }
void No(bool t = true) { cout << (t ? "No" : "Yes") << endl; }
void no(bool t = true) { cout << (t ? "no" : "yes") << endl; }
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 (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
int popcount(ll t) { return __builtin_popcountll(t); }
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 0, -1, 1}, dy = {-1, 1, 0, 0};
vi dx2 = {1, 1, 0, -1, -1, -1, 0, 1}, dy2 = {0, 1, 1, 1, 0, -1, -1, -1};
struct Setup_io {
Setup_io() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(25);
cerr << fixed << setprecision(25);
}
} setup_io;
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
// #define endl '\n'
auto start = chrono::system_clock::now();
constexpr double TL = 0.98;
double calc_seconds() {
return static_cast<double>(chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now() - start).count() / 1000000.0);
}
class HRandom {
public:
HRandom() {
random_mw = 1985;
random_mz = 2012;
}
int intRandom() {
random_mz = 36969 * (random_mz & 65535) + (random_mz >> 16);
random_mw = 18000 * (random_mw & 65535) + (random_mw >> 16);
unsigned result = (random_mz << 16) + random_mw;
return result >> 1;
}
unsigned int uintRandom_65535() {
// random_mz = 36969 * (random_mz & 65535) + (random_mz >> 16);
// random_mw = 18000 * (random_mw & 65535) + (random_mw >> 16);
// return random_mw & 65535;
const unsigned tmp = random_mw & 65535;
random_mw = 18000 * tmp + (random_mw >> 16);
return tmp;
}
unsigned int uintRandom() {
random_mz = 36969 * (random_mz & 65535) + (random_mz >> 16);
random_mw = 18000 * (random_mw & 65535) + (random_mw >> 16);
unsigned result = (random_mz << 16) + random_mw;
return result;
}
double dblRandom() {
random_mz = 36969 * (random_mz & 65535) + (random_mz >> 16);
random_mw = 18000 * (random_mw & 65535) + (random_mw >> 16);
unsigned result = (random_mz << 16) + random_mw;
return (result + 1.0) * 2.328306435454494e-10;
}
private:
unsigned random_mw;
unsigned random_mz;
};
HRandom hrandom;
static uint32_t randxor() {
static uint32_t x = 123456789;
static uint32_t y = 362436069;
static uint32_t z = 521288629;
static uint32_t w = 88675123;
uint32_t t;
t = x ^ (x << 11);
x = y;
y = z;
z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
void randxor_init() {}
double randdouble() {
return hrandom.dblRandom();
}
bool randbool(const float &p = 0.5) {
return hrandom.uintRandom_65535() < (p * 65535);
}
inline int rnd(const int n) {
assert(0 <= n);
if (n == 1) {
return 0;
}
return ((hrandom.uintRandom_65535()) * n) >> 16;
}
int rnd(const int &l, const int &r) {
assert(l <= r);
return rnd(r - l) + l;
}
class Parameter {
public:
double start_temp, end_temp;
Parameter(double start_temp = 0.5, double end_temp = 1e-6) {
this->start_temp = start_temp;
this->end_temp = end_temp;
}
static Parameter from_args(int argc, char **argv) {
return Parameter();
}
};
Parameter param;
std::default_random_engine engine(42);
constexpr int N = 45;
vector<pll> ab(N);
void input() {
int x;
cin >> x;
rep(i, N) {
cin >> ab[i].first >> ab[i].second;
}
}
double calc_score(const vector<pii> &x) {
auto now = ab;
for (auto [u, v] : x) {
pll s = now[u] + now[v];
s.first /= 2;
s.second /= 2;
now[u] = now[v] = s;
}
return log10(max(abs(now[0].first - 5e17), abs(now[0].second - 5e17)) + 1);
}
pll calc_last(const vector<pii> &x) {
auto now = ab;
for (auto [u, v] : x) {
pll s = now[u] + now[v];
s.first /= 2;
s.second /= 2;
now[u] = now[v] = s;
}
return now[0];
}
signed main(int argc, char **argv) {
#ifdef LOCAL
if (argc > 1) {
param = Parameter::from_args(argc, argv);
}
#endif
input();
constexpr int M = 50;
vector<pii> x(M);
int off = M - (N - 1);
rep(i, off) {
x[i] = {2 * i + 1, 2 * i + 2};
}
rep(i, N - 1) {
x[off + i] = {0, i + 1};
}
double score = calc_score(x);
double best_score = score;
vector<pii> best_x = x;
double temperature = param.start_temp;
int acc_rate1 = 0, acc_rate2 = 0;
rep(try_num, inf) {
if (try_num % (1 << 15) == 0) {
// DEBUG((double)acc_rate / (1 << 15));
DEBUG(make_pair((double)acc_rate1 / (1 << 15), (double)acc_rate2 / (1 << 15)));
acc_rate1 = acc_rate2 = 0;
}
if (try_num % 16 == 0) {
double sec = calc_seconds();
double rate = sec / TL;
if (rate > 1) {
DEBUG(try_num);
break;
}
temperature = param.start_temp * (1 - rate) + param.end_temp * rate;
}
int op_type = rnd(11);
if (op_type < 9) {
int idx1 = rnd(off, M - 1);
int idx2 = rnd(off, min(idx1 + 5, M));
swap(x[idx1], x[idx2]);
double new_score = calc_score(x);
double diff = score - new_score;
double prob = exp(diff / temperature);
if (randdouble() < prob) {
acc_rate1++;
score = new_score;
if (chmin(best_score, score)) {
best_x = x;
}
} else {
swap(x[idx1], x[idx2]);
}
} else if (op_type < 10) {
int idx = rnd(off, M - 3);
rep(i, 6) {
if (i % 2 == 0) {
swap(x[idx], x[idx + 1]);
} else {
swap(x[idx + 1], x[idx + 2]);
}
if (i == 5) {
break;
}
double new_score = calc_score(x);
double diff = score - new_score;
double prob = exp(diff / temperature);
if (randdouble() < prob) {
acc_rate1++;
score = new_score;
if (chmin(best_score, score)) {
best_x = x;
}
break;
}
}
} else {
int idx = rnd(off);
int b = rnd(2);
int to = rnd(N);
int ori;
if (b) {
if (x[idx].second == to) {
continue;
}
ori = x[idx].first;
x[idx].first = to;
} else {
if (x[idx].first == to) {
continue;
}
ori = x[idx].second;
x[idx].second = to;
}
double new_score = calc_score(x);
double diff = score - new_score;
double prob = exp(diff / temperature);
if (randdouble() < prob) {
acc_rate2++;
score = new_score;
if (chmin(best_score, score)) {
best_x = x;
}
} else {
if (b) {
x[idx].first = ori;
} else {
x[idx].second = ori;
}
}
}
}
DEBUG(calc_last(best_x));
int last_score = 2000000 - 100000 * best_score;
DEBUG(last_score);
cout << M << endl;
for (auto [u, v] : best_x) {
cout << u + 1 << " " << v + 1 << endl;
}
}
fuppy_kyopro