結果
問題 | No.5020 Averaging |
ユーザー |
![]() |
提出日時 | 2024-02-25 16:34:20 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 904 ms / 1,000 ms |
コード長 | 2,646 bytes |
コンパイル時間 | 7,698 ms |
コンパイル使用メモリ | 344,352 KB |
実行使用メモリ | 6,676 KB |
スコア | 32,033,489 |
最終ジャッジ日時 | 2024-02-25 16:35:16 |
合計ジャッジ時間 | 54,848 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> #include <atcoder/all> #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(a) a.begin(), a.end() typedef long double ldouble; #undef long #define long long long #define vec vector using namespace std; using mint = atcoder::modint; ostream &operator<<(ostream &os, mint a) { return os << a.val(); } template <typename T> ostream &operator<<(ostream &os, vector<T> &a) { const int n = a.size(); rep(i, n) { os << a[i]; if (i + 1 != n) os << " "; } return os; } template <typename T, size_t n> ostream &operator<<(ostream &os, array<T, n> &a) { rep(i, n) os << a[i] << " \n"[i + 1 == n]; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &i : a) is >> i; return is; } template <typename T> bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } void solve() { const auto start = chrono::system_clock::now(); constexpr int n = 45; int muda; cin >> muda; assert(muda == n); array<long, n> a, b; rep(i, n) cin >> a[i] >> b[i]; array<long, n> aa, bb; constexpr int m = 50; array<int, m> ansu, ansv; constexpr long inf = 5e17; long ans = 7e18; array<int, m> u, v; while (true) { const auto now_time = chrono::system_clock::now(); const auto elapsed_time = chrono::duration_cast<chrono::milliseconds>(now_time - start).count(); if (elapsed_time > 900) break; rep(i, m - 1) { u[i] = rand() % n; v[i] = rand() % (n - 1); if (v[i] >= u[i]) v[i]++; } rep(i, n) { aa[i] = a[i]; bb[i] = b[i]; } rep(i, m - 1) { aa[u[i]] = aa[v[i]] = (aa[u[i]] + aa[v[i]]) / 2; bb[u[i]] = bb[v[i]] = (bb[u[i]] + bb[v[i]]) / 2; } u[m - 1] = 0; rep(i, n) { v[m - 1] = i; const long a0 = aa[0], ai = aa[i]; aa[0] = aa[i] = (a0 + ai) / 2; const long b0 = bb[0], bi = bb[i]; bb[0] = bb[i] = (b0 + bi) / 2; if (chmin(ans, max(abs(aa[0] - inf), abs(bb[0] - inf)))) { rep(i, m) ansu[i] = u[i]; rep(i, m) ansv[i] = v[i]; } aa[0] = a0, aa[i] = ai; bb[0] = b0, bb[i] = bi; } } int x = m; rep(i, m) if (ansu[i] == ansv[i]) x--; cout << x << '\n'; rep(i, m) if (ansu[i] != ansv[i]) cout << ansu[i] + 1 << " " << ansv[i] + 1 << '\n'; } int main() { srand((unsigned)time(NULL)); cin.tie(nullptr); ios::sync_with_stdio(false); // cout << fixed << setprecision(400); int t = 1; // cin >> t; while (t--) solve(); return 0; }