結果
| 問題 |
No.2897 2集合間距離
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-20 21:59:25 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
// #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;
}
/*
*/