結果
問題 | No.5020 Averaging |
ユーザー | square1001 |
提出日時 | 2024-02-25 15:28:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 464 ms / 1,000 ms |
コード長 | 2,510 bytes |
コンパイル時間 | 2,551 ms |
コンパイル使用メモリ | 216,424 KB |
実行使用メモリ | 88,524 KB |
スコア | 82,096,562 |
最終ジャッジ日時 | 2024-02-25 15:28:30 |
合計ジャッジ時間 | 26,677 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge10 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 427 ms
88,524 KB |
testcase_01 | AC | 431 ms
88,524 KB |
testcase_02 | AC | 440 ms
88,524 KB |
testcase_03 | AC | 429 ms
88,524 KB |
testcase_04 | AC | 425 ms
88,524 KB |
testcase_05 | AC | 439 ms
88,524 KB |
testcase_06 | AC | 433 ms
88,524 KB |
testcase_07 | AC | 445 ms
88,524 KB |
testcase_08 | AC | 432 ms
88,524 KB |
testcase_09 | AC | 434 ms
88,524 KB |
testcase_10 | AC | 438 ms
88,524 KB |
testcase_11 | AC | 425 ms
88,524 KB |
testcase_12 | AC | 426 ms
88,524 KB |
testcase_13 | AC | 436 ms
88,524 KB |
testcase_14 | AC | 426 ms
88,524 KB |
testcase_15 | AC | 427 ms
88,524 KB |
testcase_16 | AC | 438 ms
88,524 KB |
testcase_17 | AC | 429 ms
88,524 KB |
testcase_18 | AC | 426 ms
88,524 KB |
testcase_19 | AC | 440 ms
88,524 KB |
testcase_20 | AC | 434 ms
88,524 KB |
testcase_21 | AC | 431 ms
88,524 KB |
testcase_22 | AC | 440 ms
88,524 KB |
testcase_23 | AC | 429 ms
88,524 KB |
testcase_24 | AC | 436 ms
88,524 KB |
testcase_25 | AC | 427 ms
88,524 KB |
testcase_26 | AC | 423 ms
88,524 KB |
testcase_27 | AC | 440 ms
88,524 KB |
testcase_28 | AC | 427 ms
88,524 KB |
testcase_29 | AC | 424 ms
88,524 KB |
testcase_30 | AC | 428 ms
88,524 KB |
testcase_31 | AC | 424 ms
88,524 KB |
testcase_32 | AC | 447 ms
88,524 KB |
testcase_33 | AC | 422 ms
88,524 KB |
testcase_34 | AC | 425 ms
88,524 KB |
testcase_35 | AC | 440 ms
88,524 KB |
testcase_36 | AC | 453 ms
88,524 KB |
testcase_37 | AC | 421 ms
88,524 KB |
testcase_38 | AC | 436 ms
88,524 KB |
testcase_39 | AC | 423 ms
88,524 KB |
testcase_40 | AC | 438 ms
88,524 KB |
testcase_41 | AC | 446 ms
88,524 KB |
testcase_42 | AC | 423 ms
88,524 KB |
testcase_43 | AC | 438 ms
88,524 KB |
testcase_44 | AC | 453 ms
88,524 KB |
testcase_45 | AC | 425 ms
88,524 KB |
testcase_46 | AC | 445 ms
88,524 KB |
testcase_47 | AC | 451 ms
88,524 KB |
testcase_48 | AC | 423 ms
88,524 KB |
testcase_49 | AC | 464 ms
88,524 KB |
ソースコード
#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 = 3000; vector<vector<state> > beam(N - 2); for (int v1 = 1; v1 < N; v1++) { for (int v2 = v1 + 1; v2 < N; v2++) { double x = (A[0] + A[v1] + A[v2]) / 4; double y = (B[0] + B[v1] + B[v2]) / 4; uint64_t bit = ((1ULL << N) - 1) ^ (1ULL << 0) ^ (1ULL << v1) ^ (1ULL << v2); beam[0].push_back(state(x, y, 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 - 3; level++) { double mul = pow(0.5, level != N - 3 ? level + 2 : N - 2); 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)); } } sort(beam[level].begin(), beam[level].end()); if (int(beam[level].size()) > BEAMWIDTH) { beam[level].resize(BEAMWIDTH); } cerr << "level = " << level << ": size = " << beam[level].size() << ", score = " << beam[level][0].score() << endl; } // step #3. reconstruction int pos = 0; vector<uint64_t> track; for (int level = N - 3; level >= 1; level--) { uint64_t b = beam[level][pos].bit; pos = beam[level][pos].pre; track.push_back(b); } track.push_back(beam[0][pos].bit); vector<int> ord; for (int i = 0; i < N - 3; i++) { uint64_t b = track[i] ^ track[i + 1]; int pos = __builtin_ctzll(b); ord.push_back(pos); } for (int i = N - 1; i >= 0; i--) { if (!((track[N - 3] >> i) & 1)) { ord.push_back(i); } } cout << N - 1 << endl; for (int i = 0; i < N - 3; i++) { cout << ord[i] + 1 << ' ' << ord[i + 1] + 1 << endl; } cout << ord[N - 2] + 1 << ' ' << ord[N - 1] + 1 << endl; cout << ord[N - 3] + 1 << ' ' << ord[N - 1] + 1 << endl; return 0; }