結果
問題 | No.2743 Twisted Lattice |
ユーザー | shobonvip |
提出日時 | 2024-04-21 04:09:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,458 bytes |
コンパイル時間 | 5,235 ms |
コンパイル使用メモリ | 281,564 KB |
実行使用メモリ | 35,956 KB |
最終ジャッジ日時 | 2024-10-13 02:33:39 |
合計ジャッジ時間 | 11,704 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | WA | - |
testcase_02 | AC | 285 ms
25,248 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } // defcomp template <typename T> vector<T> compress(vector<T> &X) { vector<T> vals = X; sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); return vals; } // ----- // importbisect template <typename T> int bisect_left(vector<T> &X, T v){ return lower_bound(X.begin(), X.end(), v) - X.begin(); } template <typename T> int bisect_right(vector<T> &X, T v){ return upper_bound(X.begin(), X.end(), v) - X.begin(); } // ----- int main(){ ll h,w,n; cin >> h >> w >> n; vector<ll> a(n), b(n), ind(n); vector<tuple<ll,ll,int>> tar; rep(i,0,n){ cin >> a[i] >> b[i]; tar.push_back(make_tuple(b[i],a[i],i)); } sort(tar.begin(), tar.end()); rep(i,0,n){ a[i] = get<1>(tar[i]); b[i] = get<0>(tar[i]); ind[i] = get<2>(tar[i]); } vector<ll> bc = compress(b); auto get = [&](int i) -> int { return bisect_left(bc, b[i]); }; auto hav = [&](ll z) -> bool { int tar = bisect_left(bc, z); if (tar >= (int)bc.size() || bc[tar] != z) return false; return true; }; vector<ll> cost(n, 4e18); vector<set<ll>> st((int)bc.size()); rep(i,0,n){ st[get(i)].insert(a[i]); } int piv = 0; ll nwmin = 4e18; rep(i,0,n){ int x = get(i); { auto itr = st[x].lower_bound(a[i]); if (itr != st[x].begin()){ itr--; ll val = *itr; chmin(cost[ind[i]], abs(a[i] - val)); } } { auto itr = st[x].upper_bound(a[i]); if (itr != st[x].end()){ ll val = *itr; chmin(cost[ind[i]], abs(a[i] - val)); } } for (ll y: {b[i]-1, b[i]+1}){ if (!hav(y)) continue; int z = get(y); { auto itr = st[z].upper_bound(a[i]); if (itr != st[z].begin()){ itr--; chmin(cost[ind[i]], a[i]); } } { auto itr = st[z].upper_bound(a[i]); if (itr != st[z].end()){ ll val = *itr; chmin(cost[ind[i]], val); } } } while (piv < n && b[piv] <= b[i] - 2){ chmin(nwmin, a[piv] - b[piv]); piv++; } // (1, b[i]-2) にいくのに ll geta = abs(1LL - a[i]) + 2LL; ll migiue_parameta = 1LL - (b[i] - 2LL); chmin(cost[ind[i]], (nwmin - migiue_parameta) + geta); } piv = n-1; nwmin = 4e18; rrep(i,0,n){ while(piv >= 0 && b[piv] >= b[i] + 2){ chmin(nwmin, a[piv] + b[piv]); piv--; } ll geta = abs(1LL - a[i]) + 2LL; ll migiue_parameta = 1LL + (b[i] + 2LL); chmin(cost[ind[i]], (nwmin - migiue_parameta) + geta); } rep(i,0,n){ cout << cost[i] << '\n'; } }