結果
問題 | No.5020 Averaging |
ユーザー | futamegawa |
提出日時 | 2024-02-25 15:24:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 904 ms / 1,000 ms |
コード長 | 3,051 bytes |
コンパイル時間 | 2,344 ms |
コンパイル使用メモリ | 212,840 KB |
実行使用メモリ | 6,548 KB |
スコア | 27,659,298 |
最終ジャッジ日時 | 2024-02-25 15:25:14 |
合計ジャッジ時間 | 50,337 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 903 ms
6,548 KB |
testcase_01 | AC | 903 ms
6,548 KB |
testcase_02 | AC | 903 ms
6,548 KB |
testcase_03 | AC | 903 ms
6,548 KB |
testcase_04 | AC | 903 ms
6,548 KB |
testcase_05 | AC | 903 ms
6,548 KB |
testcase_06 | AC | 903 ms
6,548 KB |
testcase_07 | AC | 902 ms
6,548 KB |
testcase_08 | AC | 903 ms
6,548 KB |
testcase_09 | AC | 903 ms
6,548 KB |
testcase_10 | AC | 903 ms
6,548 KB |
testcase_11 | AC | 903 ms
6,548 KB |
testcase_12 | AC | 903 ms
6,548 KB |
testcase_13 | AC | 903 ms
6,548 KB |
testcase_14 | AC | 903 ms
6,548 KB |
testcase_15 | AC | 904 ms
6,548 KB |
testcase_16 | AC | 903 ms
6,548 KB |
testcase_17 | AC | 903 ms
6,548 KB |
testcase_18 | AC | 903 ms
6,548 KB |
testcase_19 | AC | 903 ms
6,548 KB |
testcase_20 | AC | 903 ms
6,548 KB |
testcase_21 | AC | 902 ms
6,548 KB |
testcase_22 | AC | 902 ms
6,548 KB |
testcase_23 | AC | 903 ms
6,548 KB |
testcase_24 | AC | 903 ms
6,548 KB |
testcase_25 | AC | 903 ms
6,548 KB |
testcase_26 | AC | 903 ms
6,548 KB |
testcase_27 | AC | 903 ms
6,548 KB |
testcase_28 | AC | 904 ms
6,548 KB |
testcase_29 | AC | 903 ms
6,548 KB |
testcase_30 | AC | 903 ms
6,548 KB |
testcase_31 | AC | 903 ms
6,548 KB |
testcase_32 | AC | 903 ms
6,548 KB |
testcase_33 | AC | 903 ms
6,548 KB |
testcase_34 | AC | 903 ms
6,548 KB |
testcase_35 | AC | 903 ms
6,548 KB |
testcase_36 | AC | 902 ms
6,548 KB |
testcase_37 | AC | 902 ms
6,548 KB |
testcase_38 | AC | 903 ms
6,548 KB |
testcase_39 | AC | 904 ms
6,548 KB |
testcase_40 | AC | 903 ms
6,548 KB |
testcase_41 | AC | 903 ms
6,548 KB |
testcase_42 | AC | 903 ms
6,548 KB |
testcase_43 | AC | 903 ms
6,548 KB |
testcase_44 | AC | 903 ms
6,548 KB |
testcase_45 | AC | 903 ms
6,548 KB |
testcase_46 | AC | 903 ms
6,548 KB |
testcase_47 | AC | 903 ms
6,548 KB |
testcase_48 | AC | 903 ms
6,548 KB |
testcase_49 | AC | 903 ms
6,548 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using llu = long long unsigned; vector<ll> dx = { 0, 0, -1, 1}; vector<ll> dy = {-1, 1, 0, 0}; #define TARGET 500000000000000000LL ll scoreCal(ll a0, ll a1, ll b0, ll b1) { ll newA = (a0 + a1) / 2; ll newB = (b0 + b1) / 2; ll score = max( abs(TARGET-newA), abs(TARGET-newB)); return score; } int main() { // スタート時点のタイムスタンプ取得 auto start_time = std::chrono::high_resolution_clock::now(); int N; cin >> N; vector<ll> A(N), B(N); for (int i=0; i<N; ++i) { cin >> A[i] >> B[i]; } vector<ll> Aorg, Borg; Aorg = A; Borg = B; vector<pair<int, int>> ret; for (int i=0; i<50; ++i) { int u = 0; int v = 0; ll minScore = scoreCal(A[0], A[0], B[0], B[0]); //cout << "1 - 1 minScore = " << minScore << endl; for (int j=1; j<N; ++j) { ll score = scoreCal(A[0], A[j], B[0], B[j]); //cout << "1 - " << j+1 << " minScore = " << score << endl; if (score < minScore) { minScore = score; v = j; } } if (v == 0) { break; } ret.push_back(make_pair(u+1, v+1)); //cout << "1 - " << v+1 << " execute" << endl; ll newA = (A[u] + A[v]) / 2; ll newB = (B[u] + B[v]) / 2; A[u] = A[v] = newA; B[u] = B[v] = newB; //for (int i=0; i<N; ++i) { cout << A[i] << " " << B[i] << endl; } } ll minScore = scoreCal(A[0], A[0], B[0], B[0]); //cout << "minScore : " << minScore << endl; //ll minScore = 1e18; srand(static_cast<unsigned>(time(NULL))); while(true) { A.clear(); A = Aorg; B.clear(); B = Borg; vector<pair<int, int>> ret1; for (int i=0; i<50; ++i) { int u = rand()%N; int v = rand()%N; while (u == v) { v = rand()%N; } ret1.push_back(make_pair(u+1, v+1)); ll newA = (A[u] + A[v]) / 2; ll newB = (B[u] + B[v]) / 2; A[u] = A[v] = newA; B[u] = B[v] = newB; } ll tmpScore = scoreCal(A[0], A[0], B[0], B[0]); if (tmpScore < minScore) { minScore = tmpScore; ret.clear(); ret = ret1; } // 終了時点のタイムスタンプ取得 auto end_time = std::chrono::high_resolution_clock::now(); // 経過時間の計算 auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count(); // 経過時間と制限時間の比較 int time_limit = 900; // 制限時間(例: 2000ミリ秒) if (elapsed_time > time_limit) { break; } } //cout << "minScore : " << minScore << endl; cout << ret.size() << endl; for (auto x : ret) { cout << x.first << " " << x.second << endl; } return 0; }