結果
問題 |
No.2743 Twisted Lattice
|
ユーザー |
|
提出日時 | 2024-04-21 13:13:34 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,569 bytes |
コンパイル時間 | 3,662 ms |
コンパイル使用メモリ | 266,036 KB |
実行使用メモリ | 82,948 KB |
最終ジャッジ日時 | 2024-10-13 11:47:53 |
合計ジャッジ時間 | 9,831 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 2 WA * 6 |
ソースコード
#include<bits/stdc++.h> using namespace std; using pl=pair<long long,long long>; long long ds(pl a,pl b){ if(abs(a.second-b.second)<=1){ return abs(a.first-b.first)+abs(a.second-b.second)*min(a.first,b.first); } return a.first+b.first+abs(a.second-b.second); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); long long h,w,n; cin >> h >> w >> n; map<long long,set<pl>> mp; vector<long long> x(n),y(n); vector<pl> p(n); for(long long i=0;i<n;i++){ cin >> x[i] >> y[i]; p[i]={x[i],y[i]}; mp[y[i]].insert({x[i],i}); } vector<long long> res(n,8e18); for(long long i=0;i<n;i++){ for(long long d=-1;d<=1;d++){ long long cy=y[i]+d; if(mp[cy].empty()){continue;} auto it=mp[cy].lower_bound({x[i],i+1}); if(it!=mp[cy].end()){ res[i]=min(res[i],ds(p[i],p[(*it).second])); } it--; if(it!=mp[cy].begin()){ it--; res[i]=min(res[i],ds(p[i],p[(*it).second])); } } } // for(auto &nx : res){ // cout << nx << "\n"; // } vector<pl> vp(n); for(long long i=0;i<n;i++){ vp[i]={y[i],i}; } sort(vp.begin(),vp.end()); long long md=4e18; for(auto &nx : vp){ res[nx.second]=min(res[nx.second],md+x[nx.second]+y[nx.second]-2); md=min(md,x[nx.second]-y[nx.second]); } md=4e18; reverse(vp.begin(),vp.end()); for(auto &nx : vp){ res[nx.second]=min(res[nx.second],md+x[nx.second]-y[nx.second]-2); md=min(md,x[nx.second]+y[nx.second]); } for(auto &nx : res){ cout << nx << "\n"; } return 0; }