結果
問題 | No.5020 Averaging |
ユーザー | fuppy_kyopro |
提出日時 | 2024-02-25 13:32:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 933 ms / 1,000 ms |
コード長 | 7,872 bytes |
コンパイル時間 | 4,706 ms |
コンパイル使用メモリ | 231,564 KB |
実行使用メモリ | 6,676 KB |
スコア | 81,320,107 |
最終ジャッジ日時 | 2024-02-25 13:33:23 |
合計ジャッジ時間 | 53,648 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 932 ms
6,676 KB |
testcase_01 | AC | 931 ms
6,676 KB |
testcase_02 | AC | 932 ms
6,676 KB |
testcase_03 | AC | 932 ms
6,676 KB |
testcase_04 | AC | 932 ms
6,676 KB |
testcase_05 | AC | 932 ms
6,676 KB |
testcase_06 | AC | 932 ms
6,676 KB |
testcase_07 | AC | 932 ms
6,676 KB |
testcase_08 | AC | 932 ms
6,676 KB |
testcase_09 | AC | 932 ms
6,676 KB |
testcase_10 | AC | 932 ms
6,676 KB |
testcase_11 | AC | 932 ms
6,676 KB |
testcase_12 | AC | 933 ms
6,676 KB |
testcase_13 | AC | 931 ms
6,676 KB |
testcase_14 | AC | 932 ms
6,676 KB |
testcase_15 | AC | 932 ms
6,676 KB |
testcase_16 | AC | 932 ms
6,676 KB |
testcase_17 | AC | 932 ms
6,676 KB |
testcase_18 | AC | 932 ms
6,676 KB |
testcase_19 | AC | 932 ms
6,676 KB |
testcase_20 | AC | 932 ms
6,676 KB |
testcase_21 | AC | 932 ms
6,676 KB |
testcase_22 | AC | 931 ms
6,676 KB |
testcase_23 | AC | 932 ms
6,676 KB |
testcase_24 | AC | 932 ms
6,676 KB |
testcase_25 | AC | 932 ms
6,676 KB |
testcase_26 | AC | 932 ms
6,676 KB |
testcase_27 | AC | 932 ms
6,676 KB |
testcase_28 | AC | 931 ms
6,676 KB |
testcase_29 | AC | 932 ms
6,676 KB |
testcase_30 | AC | 932 ms
6,676 KB |
testcase_31 | AC | 932 ms
6,676 KB |
testcase_32 | AC | 932 ms
6,676 KB |
testcase_33 | AC | 931 ms
6,676 KB |
testcase_34 | AC | 932 ms
6,676 KB |
testcase_35 | AC | 932 ms
6,676 KB |
testcase_36 | AC | 932 ms
6,676 KB |
testcase_37 | AC | 932 ms
6,676 KB |
testcase_38 | AC | 932 ms
6,676 KB |
testcase_39 | AC | 932 ms
6,676 KB |
testcase_40 | AC | 932 ms
6,676 KB |
testcase_41 | AC | 932 ms
6,676 KB |
testcase_42 | AC | 932 ms
6,676 KB |
testcase_43 | AC | 931 ms
6,676 KB |
testcase_44 | AC | 933 ms
6,676 KB |
testcase_45 | AC | 932 ms
6,676 KB |
testcase_46 | AC | 932 ms
6,676 KB |
testcase_47 | AC | 932 ms
6,676 KB |
testcase_48 | AC | 932 ms
6,676 KB |
testcase_49 | AC | 932 ms
6,676 KB |
ソースコード
//* #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.93; 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 = 1.0, 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); } signed main(int argc, char **argv) { #ifdef LOCAL if (argc > 1) { param = Parameter::from_args(argc, argv); } #endif input(); constexpr int M = N - 1; vector<pii> x(M); rep(i, M) { x[i] = {0, i + 1}; } double score = calc_score(x); double best_score = score; vector<pii> best_x = x; double temperature = param.start_temp; rep(try_num, inf) { 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 idx1 = rnd(M - 1); int idx2 = rnd(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) { score = new_score; if (chmin(best_score, score)) { best_x = x; } } else { swap(x[idx1], x[idx2]); } } 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; } }