結果
問題 | No.5020 Averaging |
ユーザー | ゆにぽけ |
提出日時 | 2024-02-26 03:11:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,344 bytes |
コンパイル時間 | 1,862 ms |
コンパイル使用メモリ | 143,032 KB |
実行使用メモリ | 6,676 KB |
スコア | 1,593,557 |
最終ジャッジ日時 | 2024-02-26 03:11:56 |
合計ジャッジ時間 | 51,885 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 908 ms
6,676 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
ソースコード
#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(); //input int 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; const int sz = 50; const int half = 25; int loop = 0; const long double start_temp = 1000,end_temp = 10000; auto diff = [&M](long long a,long long b) -> long long { return max(abs(a - M),abs(b - M)); }; auto averaging = [&](long long &a,long long &b) -> void { long long x = (a + b) / 2; a = b = x; return; }; auto calc_score = [&](long long a,long long b) -> long double { return 2e6 - 1e5 * log10(diff(a,b) + 1); }; { vector<long long> C = A,D = B; vector<int> ord(N); iota(ord.begin(),ord.end(),0); sort(ord.begin(),ord.end(),[&](int i,int j) { return diff(C[i],D[i]) > diff(C[j],D[j]); }); for(int i = 2;i <= N;i++) { int id = ord[i - 1] + 1; ans.push_back(make_pair(1,id)); averaging(C[0],C[id - 1]); averaging(D[0],D[id - 1]); } score = calc_score(C[0],D[0]); } while(clock() - start_time < TIME_LIMIT) { loop++; vector<pair<int,int>> n_ans = ans; { while(true) { int i = rng() % n_ans.size(); int j = rng() % n_ans.size(); if(i == j) { continue; } swap(n_ans[i],n_ans[j]); break; } } vector<long long> C = A,D = B; for(const auto &[u,v] : n_ans) { averaging(C[u - 1],C[v - 1]); averaging(D[u - 1],D[v - 1]); } long double n_score = calc_score(C[0],D[0]); 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; } } /* 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; */ /* } */ /* { */ /* 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) */ /* { */ /* /1* int u = rng() % (N - 1) + 2; *1/ */ /* /1* int v = rng() % (N - 1) + 2; *1/ */ /* 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; */ /* /1* int v = rng() % (N - 1) + 2; *1/ */ /* /1* int U = T[u - 1] ^ 3; *1/ */ /* /1* int v = G[U][rng() % G[U].size()] + 1; *1/ */ /* if(u == n_ans[id].first) */ /* { */ /* continue; */ /* } */ /* n_ans[id].second = u; */ /* swap(n_ans[id].first,n_ans[id].second); */ /* /1* n_ans[id] = make_pair(u,v); *1/ */ /* 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; */ /* } */ /* } */ //output cout << 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(); }