結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
りあん
|
| 提出日時 | 2024-02-25 15:06:51 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 646 ms / 1,000 ms |
| コード長 | 3,982 bytes |
| コンパイル時間 | 3,746 ms |
| コンパイル使用メモリ | 272,516 KB |
| 実行使用メモリ | 6,676 KB |
| スコア | 42,048,060 |
| 最終ジャッジ日時 | 2024-02-25 15:07:54 |
| 合計ジャッジ時間 | 34,309 ms |
|
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
ソースコード
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<sys/time.h>
// #include<atcoder/segtree>
using namespace std;
// using mint = atcoder::modint998244353;
const int M = 998244353;
const long long LM = 1LL << 60;
using P = pair<int, int>;
inline unsigned int get_rand() {
static unsigned int y = 2463534242;
return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
}
long long calc(int i, int j, const vector<long long>& a, const vector<long long>& b) {
const long long T = 500000000000000000LL;
return max(abs(a[i] + a[j] - T * 2), abs(b[i] + b[j] - T * 2));
};
void op(int i, int j, vector<long long>& a, vector<long long>& b, vector<P>& ans) {
if (i == j) return;
if (ans.size() >= 50) return;
ans.emplace_back(i, j);
auto av = (a[i] + a[j]) / 2;
auto bv = (b[i] + b[j]) / 2;
a[i] = av;
a[j] = av;
b[i] = bv;
b[j] = bv;
}
pair<vector<P>, long long> greedy(vector<long long> a, vector<long long> b, vector<P> ans, const vector<P>& init) {
int n = a.size();
for (auto& i : init) {
if (ans.size() < 50) {
op(i.first, i.second, a, b, ans);
}
}
while (ans.size() < 50) {
int q = 0;
for (int i = 1; i < n; ++i) {
if (calc(0, q, a, b) > calc(0, i, a, b)) {
q = i;
}
}
if (q == 0) break;
op(0, q, a, b, ans);
}
return { ans, calc(0, 0, a, b) };
}
pair<vector<P>, long long> solve(vector<long long> a, vector<long long> b, int t) {
int n = a.size();
vector<P> best_ans;
long long best_score = LM;
vector<P> ans;
while ((int)ans.size() < 40) {
int cp = -1, cq = -1;
long long be = LM;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
long long cc = calc(i, j, a, b);
if (cc < min(calc(i, i, a, b), calc(j, j, a, b))) {
if (cp == -1 || cc < be) {
cp = i;
cq = j;
be = cc;
}
}
}
}
// vector<P> cand;
// for (int i = 0; i < n; ++i) {
// for (int j = i + 1; j < n; ++j) {
// if (calc(i, j, a, b) < min(calc(i, i, a, b), calc(j, j, a, b))) {
// cand.emplace_back(i, j);
// }
// }
// }
int p, q;
if (cp != -1 && get_rand() % t) {
// int i = get_rand() % cand.size();
// p = cand[i].first;
// q = cand[i].second;
p = cp;
q = cq;
}
else {
p = 1;
q = get_rand() % n;
while (p == q) {
p = 1;
q = get_rand() % n;
}
}
op(p, q, a, b, ans);
auto g = greedy(a, b, ans, {});
if (best_score > g.second) {
best_ans = g.first;
best_score = g.second;
}
for (int i = 1; i < n; ++i) {
auto g = greedy(a, b, ans, {{0, i}});
if (best_score > g.second) {
best_ans = g.first;
best_score = g.second;
}
}
}
return { best_ans, best_score };
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<long long> a(n), b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
vector<P> ans;
long long score = LM;
for (int _ = 0; _ < 200; ++_) {
auto res = solve(a, b, _ % 2 ? 4 : 8);
if (score > res.second) {
ans = res.first;
score = res.second;
}
}
if (ans.size() > 50) {
ans.resize(50);
}
cout << ans.size() << '\n';
for (auto& i : ans) {
cout << i.first + 1 << ' ' << i.second + 1 << '\n';
}
return 0;
}
りあん