結果
問題 | No.2897 2集合間距離 |
ユーザー | Nzt3 |
提出日時 | 2024-09-20 22:20:30 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 161 ms / 3,500 ms |
コード長 | 984 bytes |
コンパイル時間 | 2,561 ms |
コンパイル使用メモリ | 209,820 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-09-20 22:20:50 |
合計ジャッジ時間 | 5,218 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
7,424 KB |
testcase_01 | AC | 28 ms
7,424 KB |
testcase_02 | AC | 28 ms
7,296 KB |
testcase_03 | AC | 31 ms
7,296 KB |
testcase_04 | AC | 32 ms
7,424 KB |
testcase_05 | AC | 35 ms
7,424 KB |
testcase_06 | AC | 31 ms
7,296 KB |
testcase_07 | AC | 30 ms
7,424 KB |
testcase_08 | AC | 31 ms
7,552 KB |
testcase_09 | AC | 31 ms
7,296 KB |
testcase_10 | AC | 33 ms
7,424 KB |
testcase_11 | AC | 33 ms
7,552 KB |
testcase_12 | AC | 41 ms
7,680 KB |
testcase_13 | AC | 41 ms
7,680 KB |
testcase_14 | AC | 47 ms
8,576 KB |
testcase_15 | AC | 50 ms
8,320 KB |
testcase_16 | AC | 138 ms
11,008 KB |
testcase_17 | AC | 133 ms
11,008 KB |
testcase_18 | AC | 136 ms
11,008 KB |
testcase_19 | AC | 136 ms
10,880 KB |
testcase_20 | AC | 161 ms
11,008 KB |
testcase_21 | AC | 114 ms
9,472 KB |
testcase_22 | AC | 106 ms
9,212 KB |
testcase_23 | AC | 122 ms
9,216 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr int MOD=998244353; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,l,r) for(int i=(l);i<(int)(r);i++) #define all(v) v.begin(),v.end() constexpr int MAX_X=1000; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector dist(MAX_X,vector(MAX_X,(int)1e9)); queue<array<int,2>>bfs; rep(i,N){ int X,Y; cin>>X>>Y; dist[X][Y]=0; bfs.push({X,Y}); } int dx[]={0,1,0,-1}; int dy[]={-1,0,1,0}; auto bound_ok=[&](int x,int y){ return x>=0&&x<MAX_X&&y>=0&&y<MAX_X; }; while(bfs.size()){ auto [x,y]=bfs.front(); bfs.pop(); rep(i,4){ int x2=x+dx[i],y2=y+dy[i]; if(bound_ok(x2,y2)&&dist[x2][y2]>dist[x][y]+1){ dist[x2][y2]=dist[x][y]+1; bfs.push({x2,y2}); } } } int ans=1e9; int M; cin>>M; rep(i,M){ int X,Y; cin>>X>>Y; ans=min(ans,dist[X][Y]); } cout<<ans<<'\n'; }