結果
問題 | No.2743 Twisted Lattice |
ユーザー |
![]() |
提出日時 | 2024-04-21 11:45:07 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 3,000 ms |
コード長 | 1,940 bytes |
コンパイル時間 | 3,820 ms |
コンパイル使用メモリ | 279,720 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-10-13 10:12:38 |
合計ジャッジ時間 | 5,680 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 8 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic warning "-Wunused-function"using namespace std;using namespace atcoder;#define rep(i,n) for(int i = 0; i < (int)(n); i++)#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)#define all(x) begin(x), end(x)#define rall(x) rbegin(x), rend(x)template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }using ll = long long;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;struct P { int i, x, y; };} int main() {ios::sync_with_stdio(false);cin.tie(0);int h, w, n;cin >> h >> w >> n;vector<P> ps(n);rep(i, n) {ps[i].i = i;cin >> ps[i].x >> ps[i].y;}sort(all(ps), [](const auto& lhs, const auto& rhs) {return lhs.y < rhs.y || (lhs.y == rhs.y && lhs.x < rhs.x);});constexpr long long INF = 1002003004005006007;VL ans(n, INF);rep(_, 2) {ll mx = -INF;for (auto [i, x, y] : ps) {chmin(ans[i], x - 1 + y - mx);chmax(mx, 0LL + y - (x - 1));}for (auto& p : ps) p.y = w - p.y;reverse(all(ps));}for (int l = 0, r = 1; l < n; l = r++) {while (r < n && ps[r].y == ps[l].y) r++;for (int i = l; i < r; i++) {if (i > l) chmin(ans[ps[i].i], 0LL + ps[i].x - ps[i-1].x);if (i + 1 < r) chmin(ans[ps[i].i], 0LL + ps[i+1].x - ps[i].x);}for (int i = l, j = r; j < n && ps[j].y == ps[l].y + 1; j++) {while (i + 1 < r && ps[i+1].x <= ps[j].x) i++;for (int i : {i, i + 1}) if (i < r) {ll dist = (ll)abs(ps[i].x - ps[j].x) + min(ps[i].x, ps[j].x);chmin(ans[ps[i].i], dist);chmin(ans[ps[j].i], dist);}}}for (ll x : ans) cout << x << '\n';}