結果
問題 | No.157 2つの空洞 |
ユーザー | dnish |
提出日時 | 2018-06-08 11:15:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,725 bytes |
コンパイル時間 | 766 ms |
コンパイル使用メモリ | 86,024 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-12 23:14:18 |
合計ジャッジ時間 | 1,808 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,384 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | WA | - |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
4,376 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
4,380 KB |
ソースコード
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define p(s) cout<<(s)<<endl #define REP(i,n,N) for(int i=n;i<N;i++) #define RREP(i,n,N) for(int i=N-1;i>=n;i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define F first #define S second typedef long long ll; using namespace std; const int inf=1e9+7; int H,W; string s[21]; bool ok; int f[21][21]; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; vector<pair<int,int>> vt1, vt2; int main(){ cin>>W>>H; REP(i,0,H){ cin>>s[i]; } REP(i,0,H){ REP(j,0,W){ if(s[i][j]=='.'){ if(!ok){ f[i][j]=-1; ok=true; vt1.push_back({i, j}); } else if(f[i][j]==0){ f[i][j]=1; vt2.push_back({i, j}); } REP(k,0,4){ if(!CK(i+dy[k],0,H) || !CK(j+dx[k],0,W) ) continue; if(s[i+dy[k]][j+dx[k]]=='.'&&f[i+dy[k]][j+dx[k]]==0){ f[i+dy[k]][j+dx[k]] = f[i][j]; if(f[i][j]==-1){ vt1.push_back({i+dy[k], j+dx[k]}); }else if(f[i][j]==1){ vt2.push_back({i+dy[k], j+dx[k]}); } } } } } } int ans = inf; for(auto v1:vt1){ for(auto v2:vt2){ ans = min(ans, abs(v2.F-v1.F)+abs(v1.S-v2.S)-1); } } p(ans); return 0; }