結果
問題 | No.5020 Averaging |
ユーザー | ゆにぽけ |
提出日時 | 2024-02-25 15:01:31 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 957 ms / 1,000 ms |
コード長 | 4,173 bytes |
コンパイル時間 | 1,972 ms |
コンパイル使用メモリ | 153,924 KB |
実行使用メモリ | 6,676 KB |
スコア | 45,773,333 |
最終ジャッジ日時 | 2024-02-25 15:02:23 |
合計ジャッジ時間 | 51,286 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 932 ms
6,676 KB |
testcase_01 | AC | 930 ms
6,676 KB |
testcase_02 | AC | 931 ms
6,676 KB |
testcase_03 | AC | 906 ms
6,676 KB |
testcase_04 | AC | 932 ms
6,676 KB |
testcase_05 | AC | 932 ms
6,676 KB |
testcase_06 | AC | 931 ms
6,676 KB |
testcase_07 | AC | 906 ms
6,676 KB |
testcase_08 | AC | 929 ms
6,676 KB |
testcase_09 | AC | 955 ms
6,676 KB |
testcase_10 | AC | 931 ms
6,676 KB |
testcase_11 | AC | 907 ms
6,676 KB |
testcase_12 | AC | 931 ms
6,676 KB |
testcase_13 | AC | 931 ms
6,676 KB |
testcase_14 | AC | 930 ms
6,676 KB |
testcase_15 | AC | 930 ms
6,676 KB |
testcase_16 | AC | 931 ms
6,676 KB |
testcase_17 | AC | 931 ms
6,676 KB |
testcase_18 | AC | 956 ms
6,676 KB |
testcase_19 | AC | 906 ms
6,676 KB |
testcase_20 | AC | 933 ms
6,676 KB |
testcase_21 | AC | 931 ms
6,676 KB |
testcase_22 | AC | 905 ms
6,676 KB |
testcase_23 | AC | 930 ms
6,676 KB |
testcase_24 | AC | 955 ms
6,676 KB |
testcase_25 | AC | 931 ms
6,676 KB |
testcase_26 | AC | 906 ms
6,676 KB |
testcase_27 | AC | 931 ms
6,676 KB |
testcase_28 | AC | 936 ms
6,676 KB |
testcase_29 | AC | 957 ms
6,676 KB |
testcase_30 | AC | 906 ms
6,676 KB |
testcase_31 | AC | 931 ms
6,676 KB |
testcase_32 | AC | 931 ms
6,676 KB |
testcase_33 | AC | 906 ms
6,676 KB |
testcase_34 | AC | 930 ms
6,676 KB |
testcase_35 | AC | 931 ms
6,676 KB |
testcase_36 | AC | 907 ms
6,676 KB |
testcase_37 | AC | 931 ms
6,676 KB |
testcase_38 | AC | 932 ms
6,676 KB |
testcase_39 | AC | 907 ms
6,676 KB |
testcase_40 | AC | 932 ms
6,676 KB |
testcase_41 | AC | 931 ms
6,676 KB |
testcase_42 | AC | 931 ms
6,676 KB |
testcase_43 | AC | 932 ms
6,676 KB |
testcase_44 | AC | 931 ms
6,676 KB |
testcase_45 | AC | 933 ms
6,676 KB |
testcase_46 | AC | 906 ms
6,676 KB |
testcase_47 | AC | 907 ms
6,676 KB |
testcase_48 | AC | 930 ms
6,676 KB |
testcase_49 | AC | 932 ms
6,676 KB |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <array>#include <iterator>#include <string>#include <cctype>#include <cstring>#include <cstdlib>#include <cassert>#include <cmath>#include <ctime>#include <iomanip>#include <numeric>#include <stack>#include <queue>#include <map>#include <unordered_map>#include <set>#include <unordered_set>#include <bitset>#include <random>#include <utility>#include <functional>using namespace std;void Main(){int start_time = clock();//inputint N;cin >> N;vector<long long> A(N),B(N);for(int i = 0;i < N;i++){cin >> A[i] >> B[i];}const long long M = (long long)5e17;const int TIME_LIMIT = 0.9 * CLOCKS_PER_SEC;mt19937_64 rng{(unsigned)time(nullptr)};vector<pair<int,int>> ans;long double score = 0;int sz = 50;int half = 25;int loop = 0;long double start_temp = 0,end_temp = 5000;vector<vector<int>> G(1 << 2);vector<int> T(N);for(int i = 0;i < N;i++){int S = 0;if(A[i] > M){S |= 1;}if(B[i] > M){S |= 2;}if(i > 0){G[S].push_back(i);}T[i] = S;}auto diff = [&M](long long a,long long b) -> long long{return max(abs(a - M),abs(b - M));};{vector<long long> C = A,D = B;vector<int> ord(N);iota(ord.begin(),ord.end(),0);sort(ord.begin() + 1,ord.end(),[&](int i,int j){return diff(C[i],D[i]) > diff(C[j],D[j]);});for(int i = 0;i < half;i++){while(true){/* int u = rng() % (N - 1) + 2; *//* int v = rng() % (N - 1) + 2; */int u = ord[N - i - 1] + 1;int U = T[u - 1] ^ 3;int v = G[U][rng() % G[U].size()] + 1;if(u == v){continue;}{long long x = (C[u - 1] + C[v - 1]) / 2;C[u - 1] = C[v - 1] = x;}{long long x = (D[u - 1] + D[v - 1]) / 2;D[u - 1] = D[v - 1] = x;}ans.push_back(make_pair(u,v));break;}}iota(ord.begin(),ord.end(),0);sort(ord.begin() + 1,ord.end(),[&](int i,int j){return diff(C[i],D[i]) > diff(C[j],D[j]);});for(int i = N - (sz - half);i < N;i++){int id = ord[i];{long long x = (C[0] + C[id]) / 2;C[0] = C[id] = x;}{long long x = (D[0] + D[id]) / 2;D[0] = D[id] = x;}ans.push_back(make_pair(1,id + 1));}score = 2e6 - 1e5 * log10(diff(C[0],D[0]) + 1);}while(clock() - start_time < TIME_LIMIT){loop++;vector<pair<int,int>> n_ans(ans.begin(),ans.begin() + half);{int id = rng() % half;while(true){int u = rng() % (N - 1) + 2;/* int v = rng() % (N - 1) + 2; *//* int U = T[u - 1] ^ 3; *//* int v = G[U][rng() % G[U].size()] + 1; */if(u == n_ans[id].first){continue;}n_ans[id].second = u;swap(n_ans[id].first,n_ans[id].second);/* n_ans[id] = make_pair(u,v); */break;}}long double n_score = 0;vector<long long> C = A,D = B;for(const auto &[u,v] : n_ans){{long long x = (C[u - 1] + C[v - 1]) / 2;C[u - 1] = C[v - 1] = x;}{long long x = (D[u - 1] + D[v - 1]) / 2;D[u - 1] = D[v - 1] = x;}}vector<int> ord(N);iota(ord.begin(),ord.end(),0);sort(ord.begin() + 1,ord.end(),[&](int i,int j){return diff(C[i],D[i]) > diff(C[j],D[j]);});for(int i = N - (sz - half);i < N;i++){int id = ord[i];{long long x = (C[0] + C[id]) / 2;C[0] = C[id] = x;}{long long x = (D[0] + D[id]) / 2;D[0] = D[id] = x;}n_ans.push_back(make_pair(1,id + 1));}n_score = 2e6 - 1e5 * log10(diff(C[0],D[0]) + 1);long double temp = start_temp + (end_temp - start_temp) * (clock() - start_time) / TIME_LIMIT;long double prob = exp((n_score - score) / temp);if(prob > (long double)(rng() % M) / M){swap(ans,n_ans);score = n_score;}}//outputcout << ans.size() << "\n";for(int i = 0;i < (int)ans.size();i++){cout << ans[i].first << " " << ans[i].second << "\n";}cerr << "Score : " << score << "\n";cerr << "Loop : " << loop << "\n";}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int tt = 1;/* cin >> tt; */while(tt--) Main();}