結果
問題 |
No.3292 World Map Distance
|
ユーザー |
|
提出日時 | 2025-10-03 23:19:34 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,649 bytes |
コンパイル時間 | 4,944 ms |
コンパイル使用メモリ | 335,084 KB |
実行使用メモリ | 12,728 KB |
最終ジャッジ日時 | 2025-10-03 23:19:43 |
合計ジャッジ時間 | 8,771 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 1 WA * 33 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); } istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } typedef long long ll; typedef vector<vector<int>> Graph; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define FOR(i,l,r) for (int i = l;i < (int)(r); i++) #define rep(i,n) for (int i = 0;i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define my_sort(x) sort(x.begin(), x.end()) #define my_max(x) *max_element(all(x)) #define my_min(x) *min_element(all(x)) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30) - 1; const ll LINF = (1LL<<62) - 1; const int MOD = 998244353; const int MOD2 = 1e9+7; const double PI = acos(-1); vector<int> di = {1,0,-1,0}; vector<int> dj = {0,1,0,-1}; #ifdef LOCAL # include <debug_print.hpp> # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast<void>(0)) #endif /** * @brief Slope-Trick * * @see https://maspypy.com/slope-trick-1-%E8%A7%A3%E8%AA%AC%E7%B7%A8 */ template <typename T> struct SlopeTrick { const T INF = numeric_limits<T>::max() / 3; T min_f; priority_queue<T, vector<T>, less<> > L; priority_queue<T, vector<T>, greater<> > R; T add_l, add_r; private: void push_R(const T& a) { R.push(a - add_r); } T top_R() const { if (R.empty()) return INF; else return R.top() + add_r; } T pop_R() { T val = top_R(); if (not R.empty()) R.pop(); return val; } void push_L(const T& a) { L.push(a - add_l); } T top_L() const { if (L.empty()) return -INF; else return L.top() + add_l; } T pop_L() { T val = top_L(); if (not L.empty()) L.pop(); return val; } size_t size() { return L.size() + R.size(); } public: SlopeTrick() : min_f(0), add_l(0), add_r(0) {} struct Query { T lx, rx, min_f; }; // return min f(x) Query query() const { return (Query){top_L(), top_R(), min_f}; } // f(x) += a void add_all(const T& a) { min_f += a; } // add \_ // f(x) += max(a - x, 0) void add_a_minus_x(const T& a) { min_f += max(T(0), a - top_R()); push_R(a); push_L(pop_R()); } // add _/ // f(x) += max(x - a, 0) void add_x_minus_a(const T& a) { min_f += max(T(0), top_L() - a); push_L(a); push_R(pop_L()); } // add \/ // f(x) += abs(x - a) void add_abs(const T& a) { add_a_minus_x(a); add_x_minus_a(a); } // \/ -> \_ // f_{new} (x) = min f(y) (y <= x) void clear_right() { while (not R.empty()) R.pop(); } // \/ -> _/ // f_{new} (x) = min f(y) (y >= x) void clear_left() { while (not L.empty()) L.pop(); } // \/ -> \_/ // f_{new} (x) = min f(y) (x-b <= y <= x-a) void shift(const T& a, const T& b) { assert(a <= b); add_l += a; add_r += b; } // \/. -> .\/ // f_{new} (x) = f(x - a) void shift(const T& a) { shift(a, a); } // L, R を破壊する T get(const T& x) { T ret = min_f; while (not L.empty()) { ret += max(T(0), pop_L() - x); } while (not R.empty()) { ret += max(T(0), x - pop_R()); } return ret; } void merge(SlopeTrick& st) { if (st.size() > size()) { swap(st.L, L); swap(st.R, R); swap(st.add_l, add_l); swap(st.add_r, add_r); swap(st.min_f, min_f); } while (not st.R.empty()) { add_x_minus_a(st.pop_R()); } while (not st.L.empty()) { add_a_minus_x(st.pop_L()); } min_f += st.min_f; } }; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); SlopeTrick<ll> stx, sty; ll N, X, Y; cin >> N >> X >> Y; vector<ll> x(N), y(N); rep(i, N){ cin >> x[i] >> y[i]; stx.add_abs(x[i] + (X / 2)); sty.add_abs(y[i] + (Y / 2)); } auto qx = stx.query(); auto qy = sty.query(); debug(qx.lx, qx.rx, qx.min_f); debug(qy.lx, qy.rx, qy.min_f); cout << N * (X + Y) / 2 - qx.min_f - qy.min_f << endl; }