結果
問題 | No.1998 Manhattan Restaurant |
ユーザー |
![]() |
提出日時 | 2022-03-19 16:29:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,243 bytes |
コンパイル時間 | 865 ms |
コンパイル使用メモリ | 81,752 KB |
最終ジャッジ日時 | 2025-01-28 10:47:26 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 11 TLE * 14 MLE * 6 |
ソースコード
#include <iostream> #include <vector> #define rep(i, l, n) for (int i = (l); i < (n); i++) using namespace std; using ll = long long; using Pair = pair<ll, ll>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T> >; bool func(ll N, VV<Pair>& route, ll d) { V<ll> c(N); rep(v, 0, N) { if (c[v]) { continue; } c[v] = 1; V<ll> que = { v }; while (que.empty() == false) { ll now = que[que.size() - 1]; que.pop_back(); for (auto& r : route[now]) { ll nv = r.first, nd = r.second; if (nd <= d) { continue; } if (c[nv] == 0) { c[nv] = -c[now]; que.push_back(nv); } else if (c[nv] == c[now]) { return false; } } } } return true; } int main(void) { ll N; cin >> N; VV<ll> P(N, V<ll>(2)); rep(i, 0, N) { cin >> P[i][0] >> P[i][1]; } VV<Pair> route(N, V<Pair>(0)); rep(i, 0, N - 1) { rep(j, i + 1, N) { ll d = abs(P[i][0] - P[j][0]) + abs(P[i][1] - P[j][1]); route[i].push_back({ j,d }); route[j].push_back({ i,d }); } } ll ok = 4000000001, ng = -1; while (ok - ng > 1) { ll d = (ok + ng) / 2; if (func(N, route, d)) { ok = d; } else { ng = d; } } ll ans = ok / 2; cout << ans << endl; return 0; }