結果

問題 No.2743 Twisted Lattice
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-20 12:16:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,836 bytes
コンパイル時間 2,634 ms
コンパイル使用メモリ 224,768 KB
実行使用メモリ 43,920 KB
最終ジャッジ日時 2024-04-20 12:16:41
合計ジャッジ時間 8,276 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 500 ms
43,880 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    long long H,W,N; cin >> H >> W >> N;
    
    map<long long,vector<long long>> X;
    vector<tuple<long long,long long,long long>> XY(N);
    long long idx = 0;
    for(auto &[x,y,pos] : XY) cin >> x >> y,swap(x,y),X[x].push_back(y),pos = idx++;
    long long inf = 4e18;
    vector<long long> answer(N,inf);
    for(long long i=0; i<N; i++){
        auto[x,y,ig] = XY.at(i);
        auto &look = X[x];
        long long pos = upper_bound(look.begin(),look.end(),y)-look.begin();
        if(pos != look.size()) answer.at(i) = look.at(pos)-y;
        pos--; pos--;
        if(pos >= 0) answer.at(i) = min(answer.at(i),y-look.at(pos));

        auto itr = X.find(x-1);
        if(itr != X.end() && X[x-1].size()) answer.at(i) = min(answer.at(i),max(y,X[x-1].at(0)));
        itr = X.find(x+1);
        if(itr != X.end() && X[x+1].size()) answer.at(i) = min(answer.at(i),max(y,X[x+1].at(0)));
    }
    
    sort(XY.rbegin(),XY.rend());
    set<pair<long long,long long>> man;
    for(auto [x,y,pos] : XY){
        if(man.size() == 0){man.insert({x+y,pos}); continue;}
        auto[mind,pos2] = *man.begin();
        long long now = mind-1-x + y-1; 
        answer.at(pos) = min(answer.at(pos),now);
        answer.at(pos2) = min(answer.at(pos2),now);
        man.insert({x+y,pos}); 
    }
    reverse(XY.begin(),XY.end());
    man.clear();
    for(auto [x,y,pos] : XY){
        if(man.size() == 0){man.insert({y-x,pos}); continue;}
        auto[mind,pos2] = *man.begin();
        long long now = x+mind-1 + y-1;
        answer.at(pos) = min(answer.at(pos),now);
        answer.at(pos2) = min(answer.at(pos2),now);
        man.insert({y-x,pos});        
    }

    for(auto ans : answer) cout << ans << "\n";
}
0