結果
問題 | No.2743 Twisted Lattice |
ユーザー | cho435 |
提出日時 | 2024-04-20 02:42:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 426 ms / 3,000 ms |
コード長 | 1,345 bytes |
コンパイル時間 | 2,239 ms |
コンパイル使用メモリ | 217,464 KB |
実行使用メモリ | 34,732 KB |
最終ジャッジ日時 | 2024-04-20 02:42:27 |
合計ジャッジ時間 | 6,723 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 341 ms
34,708 KB |
testcase_01 | AC | 142 ms
9,748 KB |
testcase_02 | AC | 141 ms
11,148 KB |
testcase_03 | AC | 375 ms
34,500 KB |
testcase_04 | AC | 383 ms
34,432 KB |
testcase_05 | AC | 402 ms
34,528 KB |
testcase_06 | AC | 401 ms
34,564 KB |
testcase_07 | AC | 426 ms
34,732 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) int main(){ int h,w,n; cin>>h>>w>>n; vector<int> a(n),b(n); rep(i,n) cin>>a.at(i)>>b.at(i); vector<ll> ans(n,1e18); map<int,vector<pair<ll,ll>>> mp; rep(i,n) mp[b.at(i)].push_back({a.at(i),i}); for(auto&[k,v]:mp){ sort(v.begin(),v.end()); int m=v.size(); rep(i,m){ if(i>0) ans.at(v.at(i).second)=min(ans.at(v.at(i).second),v.at(i).first-v.at(i-1).first); if(i+1<m) ans.at(v.at(i).second)=min(ans.at(v.at(i).second),v.at(i+1).first-v.at(i).first); } } for(auto&[k,v]:mp){ for(int shf:{-1,1}){ if(mp.count(k-shf)){ auto[mn,j]=mp.at(k-shf).front(); for(auto[p,i]:v){ ll tmp=0; tmp+=min(mn,p); tmp+=abs(mn-p); ans.at(i)=min(ans.at(i),tmp); } } } } vector<pair<int,ll>> vp; for(auto&[k,v]:mp){ vp.push_back({k,v.front().first}); } int m=vp.size(); vector<ll> rmn(m,1e18),lmn(m,1e18); rep(i,m-1){ lmn.at(i+1)=min(lmn.at(i),vp.at(i).second)+vp.at(i+1).first-vp.at(i).first; } for(int i=m-1;i>0;i--){ rmn.at(i-1)=min(rmn.at(i),vp.at(i).second)+vp.at(i).first-vp.at(i-1).first; } rep(i,m){ auto &v=mp.at(vp.at(i).first); ll tmp=min(lmn.at(i),rmn.at(i)); for(auto[p,j]:v){ ans.at(j)=min(ans.at(j),tmp+p-2); } } rep(i,n) cout<<ans.at(i)<<"\n"; }