結果
問題 |
No.3292 World Map Distance
|
ユーザー |
|
提出日時 | 2025-10-04 00:23:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,529 bytes |
コンパイル時間 | 3,465 ms |
コンパイル使用メモリ | 293,200 KB |
実行使用メモリ | 25,088 KB |
最終ジャッジ日時 | 2025-10-04 00:23:27 |
合計ジャッジ時間 | 11,846 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 WA * 1 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/fenwicktree.hpp> #include <atcoder/segtree.hpp> #include <atcoder/modint.hpp> #include <atcoder/dsu.hpp> #include <atcoder/lazysegtree.hpp> using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; template <class T> using max_heap = priority_queue<T>; template <class T> using min_heap = priority_queue<T, vector<T>, greater<>>; ll ll_min = numeric_limits<ll>::min(); ll ll_max = numeric_limits<ll>::max(); ll ALPHABET_N = 26; using mint = modint998244353; #define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++) #define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++) #define all(a) a.begin(), a.end() int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, x, y; cin >> n >> x >> y; vector<ll> X1(n), X2(n); rep(i, n) cin >> X1[i] >> X2[i]; rep(i, n) { X1[i]--; X2[i]--; } auto get_max_cost = [&](vector<ll> X, ll d) -> ll { // (x, type, val, idx) set<tuple<ll, ll, ll, ll>> ev; ll res = 0; ll minus = 0; ll minus_cnt = 0; ll plus = 0; ll plus_cnt = 0; rep(i, n) { ll x1 = X[i]; ll x1m = -d + x1; ll change_p1 = x1 - (d / 2); if (change_p1 >= 0) { ev.insert({change_p1, 0, x1m, i}); minus_cnt++; minus += x1m; } else { ev.insert({x1, 1, x1, i}); plus_cnt++; plus += x1; } } res = plus - minus; while (!ev.empty() && d > get<0>(*(ev.begin()))) { auto [x_ev_, type_, val_, idx_] = *ev.begin(); ll tgt_x_ev = x_ev_; if (tgt_x_ev > 0) { res = max(res, plus - plus_cnt * (tgt_x_ev - 1) + minus_cnt * (tgt_x_ev - 1) - minus); } while (!ev.empty() && tgt_x_ev == get<0>(*(ev.begin()))) { auto [x_ev, type, val, idx] = *ev.begin(); ev.erase(ev.begin()); if (type == 0) { minus_cnt--; minus -= val; plus_cnt++; plus += X[idx]; ev.insert({X[idx], 1, X[idx], idx}); } if (type == 1) { plus_cnt--; plus -= val; minus_cnt++; minus += X[idx]; ll nex = X[idx] + (d + 1) / 2; ev.insert({nex, 2, val, idx}); } if (type == 2) { minus_cnt--; minus -= val; plus_cnt++; plus += d + X[idx]; } } // res = max(res, plus - plus_cnt * x_ev_ + minus_cnt * x_ev_ - minus); res = max(res, plus - plus_cnt * tgt_x_ev + minus_cnt * tgt_x_ev - minus); } res = max(res, plus - plus_cnt * (d - 1) + minus_cnt * (d - 1) - minus); return res; }; cout << get_max_cost(X1, x) + get_max_cost(X2, y) << endl; return 0; }