結果
問題 | No.2743 Twisted Lattice |
ユーザー |
|
提出日時 | 2024-04-20 12:18:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 929 ms / 3,000 ms |
コード長 | 1,891 bytes |
コンパイル時間 | 2,852 ms |
コンパイル使用メモリ | 225,572 KB |
最終ジャッジ日時 | 2025-02-21 06:18:56 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 8 |
ソースコード
#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++;for(auto &[k,v] : X) sort(v.begin(),v.end());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";}