結果
問題 | No.2436 Min Diff Distance |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-12-17 20:20:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 217 ms / 2,000 ms |
コード長 | 3,153 bytes |
コンパイル時間 | 1,605 ms |
コンパイル使用メモリ | 123,032 KB |
実行使用メモリ | 11,304 KB |
最終ジャッジ日時 | 2024-09-27 08:05:47 |
合計ジャッジ時間 | 5,572 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,944 KB |
testcase_03 | AC | 217 ms
11,300 KB |
testcase_04 | AC | 216 ms
11,300 KB |
testcase_05 | AC | 215 ms
11,140 KB |
testcase_06 | AC | 216 ms
11,304 KB |
testcase_07 | AC | 217 ms
11,176 KB |
testcase_08 | AC | 215 ms
11,264 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 96 ms
11,172 KB |
testcase_12 | AC | 85 ms
11,168 KB |
testcase_13 | AC | 141 ms
8,704 KB |
testcase_14 | AC | 23 ms
6,940 KB |
testcase_15 | AC | 209 ms
11,032 KB |
testcase_16 | AC | 95 ms
7,192 KB |
testcase_17 | AC | 183 ms
10,100 KB |
testcase_18 | AC | 162 ms
9,480 KB |
testcase_19 | AC | 186 ms
10,216 KB |
testcase_20 | AC | 125 ms
8,252 KB |
testcase_21 | AC | 52 ms
6,940 KB |
testcase_22 | AC | 23 ms
6,944 KB |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") constexpr int INF = 1001001001; void bChmax(vector<int> &bit, int pos, int val) { const int bitN = bit.size(); for (int x = pos; x < bitN; x |= x + 1) chmax(bit[x], val); } int bMax(const vector<int> &bit, int pos) { int ret = -INF; for (int x = pos; x > 0; x &= x - 1) chmax(ret, bit[x - 1]); return ret; } int N; vector<int> X, Y; int main() { for (; ~scanf("%d", &N); ) { X.resize(N); Y.resize(N); for (int i = 0; i < N; ++i) { scanf("%d%d", &X[i], &Y[i]); --X[i]; --Y[i]; } vector<int> A(N), B(N); for (int i = 0; i < N; ++i) { A[i] = X[i] + Y[i]; B[i] = X[i] - Y[i]; } const int minA = *min_element(A.begin(), A.end()); const int maxA = *max_element(A.begin(), A.end()); const int minB = *min_element(B.begin(), B.end()); const int maxB = *max_element(B.begin(), B.end()); vector<int> ansMax(N); for (int i = 0; i < N; ++i) { ansMax[i] = max({A[i] - minA, maxA - A[i], B[i] - minB, maxB - B[i]}); } vector<int> ansMin(N, INF); for (int dir = 0; dir < 4; ++dir) { // <= X[i], <= Y[i] vector<pair<pair<int, int>, int>> ps(N); for (int i = 0; i < N; ++i) { ps[i] = make_pair(make_pair(X[i], Y[i]), i); } sort(ps.begin(), ps.end()); vector<int> bit(N, -INF); for (const auto &p : ps) { const int i = p.second; const int res = bMax(bit, Y[i] + 1); chmin(ansMin[i], X[i] + Y[i] - res); bChmax(bit, Y[i], X[i] + Y[i]); } if (dir & 1) { for (int i = 0; i < N; ++i) X[i] = N - 1 - X[i]; } else { for (int i = 0; i < N; ++i) Y[i] = N - 1 - Y[i]; } } cerr<<"ansMax = "<<ansMax<<endl; cerr<<"ansMin = "<<ansMin<<endl; int ans = INF; for (int i = 0; i < N; ++i) { chmin(ans, ansMax[i] - ansMin[i]); } printf("%d\n", ans); } return 0; }