結果
| 問題 |
No.2743 Twisted Lattice
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 12:10:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,767 bytes |
| コンパイル時間 | 2,490 ms |
| コンパイル使用メモリ | 222,180 KB |
| 最終ジャッジ日時 | 2025-02-21 06:18:12 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 WA * 5 RE * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H,W,N; cin >> H >> W >> N;
map<long long,vector<long long>> X;
vector<tuple<long long,long long,int>> XY(N);
int 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(int i=0; i<N; i++){
auto[x,y,ig] = XY.at(i);
auto &look = X[x];
int 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 != -1) answer.at(i) = min(answer.at(i),y-look.at(pos));
auto itr = X.find(x-1);
if(itr != X.end()) answer.at(i) = min(answer.at(i),max(y,X[x-1].at(0)));
itr = X.find(x+1);
if(itr != X.end()) answer.at(i) = min(answer.at(i),max(y,X[x+1].at(0)));
}
sort(XY.rbegin(),XY.rend());
set<pair<long long,int>> 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";
}