結果

問題 No.2743 Twisted Lattice
ユーザー kenken714kenken714
提出日時 2024-04-18 14:44:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,252 ms / 3,000 ms
コード長 2,112 bytes
コンパイル時間 3,344 ms
コンパイル使用メモリ 229,000 KB
実行使用メモリ 66,192 KB
最終ジャッジ日時 2024-04-18 14:44:17
合計ジャッジ時間 15,619 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,240 ms
66,192 KB
testcase_01 AC 860 ms
37,840 KB
testcase_02 AC 748 ms
38,556 KB
testcase_03 AC 1,151 ms
66,012 KB
testcase_04 AC 1,227 ms
66,056 KB
testcase_05 AC 1,234 ms
66,064 KB
testcase_06 AC 1,248 ms
65,928 KB
testcase_07 AC 1,252 ms
65,936 KB
testcase_08 AC 7 ms
9,728 KB
testcase_09 AC 7 ms
9,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

vector<P> v;
map<ll, ll> to, fr;
map<P, ll> pos;
vector<ll> g[210000], ans(210000, INF);
priority_queue<P, vector<P>, greater<P>> qf, qb;
int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    REP(i, n){
        ll a, b;
        cin >> a >> b;
        v.push_back(P(b, a));
        fr[b]++;
        pos[P(b, a)] = i;
    }
    ll itr = 0;
    for (auto& i : fr) {
        to[itr] = i.first;
        i.second = itr;
        itr++;
    }
    sort(ALL(v));
    REP(i, n) g[fr[v[i].first]].push_back(v[i].second);
    REP(i, 210000) sort(ALL(g[i]));
    REP(i, n) qb.push(P(v[i].second - 1 + v[i].first, fr[v[i].first]));
    REP(i, n){
        ll row = fr[v[i].first];
        //おなじれつ
        auto it = lower_bound(ALL(g[row]), v[i].second);
        if (it != g[row].begin()) ans[pos[v[i]]] = min(ans[pos[v[i]]], abs(*(it - 1) - v[i].second));
        if (it + 1 != g[row].end()) ans[pos[v[i]]] = min(ans[pos[v[i]]], abs(*(it + 1) - v[i].second));
        //となりれつ
        if (row >= 0 and to[row - 1] == v[i].first - 1 and g[row - 1].size()) ans[pos[v[i]]] = min(ans[pos[v[i]]], max(g[row - 1][0], v[i].second));
        if (to[row + 1] == v[i].first + 1 and g[row + 1].size()) ans[pos[v[i]]] = min(ans[pos[v[i]]], max(g[row + 1][0], v[i].second));
        //とおいれつ
        while(!qb.empty() and qb.top().second <= row) qb.pop();
        if (!qb.empty()) ans[pos[v[i]]] = min(ans[pos[v[i]]], qb.top().first - v[i].first + v[i].second - 1);
        if (!qf.empty()) ans[pos[v[i]]] = min(ans[pos[v[i]]], qf.top().first + v[i].first + v[i].second - 1);
        qf.push(P(v[i].second - 1 - v[i].first, fr[v[i].first]));
    }
    REP(i, n)cout << ans[i] << endl;
}
0