結果
問題 | No.5020 Averaging |
ユーザー | square1001 |
提出日時 | 2024-02-25 17:28:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,716 bytes |
コンパイル時間 | 2,522 ms |
コンパイル使用メモリ | 218,508 KB |
実行使用メモリ | 531,964 KB |
スコア | 0 |
最終ジャッジ日時 | 2024-02-25 17:29:25 |
合計ジャッジ時間 | 47,210 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | MLE | - |
testcase_02 | MLE | - |
testcase_03 | MLE | - |
testcase_04 | MLE | - |
testcase_05 | MLE | - |
testcase_06 | MLE | - |
testcase_07 | MLE | - |
testcase_08 | MLE | - |
testcase_09 | MLE | - |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
testcase_16 | MLE | - |
testcase_17 | MLE | - |
testcase_18 | MLE | - |
testcase_19 | MLE | - |
testcase_20 | MLE | - |
testcase_21 | MLE | - |
testcase_22 | MLE | - |
testcase_23 | MLE | - |
testcase_24 | MLE | - |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | MLE | - |
testcase_29 | MLE | - |
testcase_30 | MLE | - |
testcase_31 | MLE | - |
testcase_32 | MLE | - |
testcase_33 | MLE | - |
testcase_34 | MLE | - |
testcase_35 | MLE | - |
testcase_36 | MLE | - |
testcase_37 | MLE | - |
testcase_38 | MLE | - |
testcase_39 | MLE | - |
testcase_40 | MLE | - |
testcase_41 | MLE | - |
testcase_42 | MLE | - |
testcase_43 | MLE | - |
testcase_44 | MLE | - |
testcase_45 | MLE | - |
testcase_46 | MLE | - |
testcase_47 | MLE | - |
testcase_48 | MLE | - |
testcase_49 | MLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; class state { public: double x, y; uint64_t bit; int pre; state() : x(0.0), y(0.0), bit(0), pre(-1) {} state(double x_, double y_, uint64_t bit_, int pre_) : x(x_), y(y_), bit(bit_), pre(pre_) {} double score() const { return max(abs(x), abs(y)); } bool operator<(const state& s) const { return score() < s.score(); } }; int main() { // step #1. input int N; cin >> N; vector<double> A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; A[i] -= 5.0e+17; B[i] -= 5.0e+17; } // step #2. beam search const int BEAMWIDTH = 18000; vector<vector<state> > beam(N); for (int i = 1; i < N; i++) { uint64_t bit = ((1ULL << N) - 1) ^ (1ULL << i); beam[0].push_back(state(A[i] * 0.5, B[i] * 0.5, bit, -1)); } sort(beam[0].begin(), beam[0].end()); if (int(beam[0].size()) > BEAMWIDTH) { beam[0].resize(BEAMWIDTH); } for (int level = 1; level <= N - 1; level++) { double mul = pow(0.5, min(level + 1, N - 1)); for (int i = 0; i < int(beam[level - 1].size()); i++) { state s = beam[level - 1][i]; uint64_t b = s.bit; while (b != 0) { int pos = __builtin_ctzll(b); b ^= 1ULL << pos; double x = s.x + A[pos] * mul; double y = s.y + B[pos] * mul; uint64_t bit = s.bit ^ (1ULL << pos); beam[level].push_back(state(x, y, bit, i)); } } if (int(beam[level].size()) > BEAMWIDTH) { nth_element(beam[level].begin(), beam[level].begin() + BEAMWIDTH, beam[level].end()); beam[level].resize(BEAMWIDTH); } // cerr << "level = " << level << ": size = " << beam[level].size() << ", score = " << (*min_element(beam[level].begin(), beam[level].end())).score() << ", back = " << beam[level].back().score() << endl; } // step #3. construct depth vector<int> depth(N, -1); int idx = min_element(beam[N - 1].begin(), beam[N - 1].end()) - beam[N - 1].begin(); uint64_t prebit = beam[N - 1][idx].bit; for (int i = N - 1; i >= 0; i--) { uint64_t nxtbit = (i != 0 ? beam[i - 1][beam[i][idx].pre].bit : (1ULL << N) - 1); uint64_t bitdiff = prebit ^ nxtbit; depth[__builtin_ctzll(bitdiff)] = min(i + 1, N - 1); prebit = nxtbit; if (i != 0) { idx = beam[i][idx].pre; } } // step #4. construct answer vector<array<int, 2> > answer; vector<int> curdepth = depth; while (curdepth[0] != 0) { int p1 = max_element(curdepth.begin(), curdepth.end()) - curdepth.begin(); int p2 = max_element(curdepth.begin() + p1 + 1, curdepth.end()) - curdepth.begin(); answer.push_back({p1, p2}); curdepth[p1] -= 1; curdepth[p2] = -1; } // step #5. output cout << answer.size() << endl; for (array<int, 2> v : answer) { cout << v[0] + 1 << ' ' << v[1] + 1 << endl; } return 0; }