結果
問題 | No.2897 2集合間距離 |
ユーザー | Aeren |
提出日時 | 2024-09-20 21:59:25 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,088 ms / 3,500 ms |
コード長 | 1,581 bytes |
コンパイル時間 | 3,554 ms |
コンパイル使用メモリ | 270,628 KB |
実行使用メモリ | 10,960 KB |
最終ジャッジ日時 | 2024-09-20 21:59:57 |
合計ジャッジ時間 | 21,405 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 4 ms
6,940 KB |
testcase_12 | AC | 8 ms
6,944 KB |
testcase_13 | AC | 12 ms
6,944 KB |
testcase_14 | AC | 58 ms
6,944 KB |
testcase_15 | AC | 104 ms
6,940 KB |
testcase_16 | AC | 2,088 ms
10,956 KB |
testcase_17 | AC | 2,079 ms
10,844 KB |
testcase_18 | AC | 2,058 ms
10,824 KB |
testcase_19 | AC | 2,055 ms
10,880 KB |
testcase_20 | AC | 2,079 ms
10,812 KB |
testcase_21 | AC | 2,054 ms
10,804 KB |
testcase_22 | AC | 2,050 ms
10,960 KB |
testcase_23 | AC | 2,048 ms
10,672 KB |
ソースコード
// #include <bits/allocator.h> // Temp fix for gcc13 global pragma // #pragma GCC target("avx2,bmi2,popcnt,lzcnt") // #pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> // #include <x86intrin.h> using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif #ifdef LOCAL #include "Debug.h" #else #define debug_endl() 42 #define debug(...) 42 #define debug2(...) 42 #define debugbin(...) 42 #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n; cin >> n; vector<array<int, 2>> a(n); for(auto &[x, y]: a){ cin >> x >> y; } int m; cin >> m; vector<array<int, 2>> b(m); for(auto &[x, y]: b){ cin >> x >> y; } int res = numeric_limits<int>::max(); for(auto rep = 2; rep; -- rep){ for(auto rep = 2; rep; -- rep){ vector<vector<array<int, 2>>> event(2001); debug(a); debug(b); for(auto [x, y]: a){ event[x].push_back({0, y}); } for(auto [x, y]: b){ event[x].push_back({1, y}); } vector<int> opt_dif(2001, numeric_limits<int>::min() / 2); for(auto dif = 0; dif <= 2000; ++ dif){ ranges::sort(event[dif] | ranges::views::reverse); for(auto [type, sum]: event[dif]){ if(type == 0){ for(auto psum = 0; psum <= 2000; ++ psum){ res = min(res, abs(sum - psum) + dif - opt_dif[psum]); } } else{ opt_dif[sum] = max(opt_dif[sum], dif); } } } swap(a, b); } for(auto &[x, y]: a){ x = 1000 - x; } for(auto &[x, y]: b){ x = 1000 - x; } } cout << res << "\n"; return 0; } /* */