結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-07 22:57:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,408 bytes |
| コンパイル時間 | 1,740 ms |
| コンパイル使用メモリ | 179,896 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 10:35:30 |
| 合計ジャッジ時間 | 2,667 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
#define mini min_element
#define maxi max_element
#define sum(a, b) accumulate(a, b)
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << "\n";}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
vector<pii> f(vector<string>& c, int y, int x, int h, int w) {
c[y][x] = '#';
vector<pii> ret = {mp(y, x)};
deque<pii> dp{mp(y, x)};
int ny, nx;
while (!dp.empty()) {
tie(y, x) = dp.front(); dp.pop_front();
rep(i, 0, 4) {
ny = y + dy[i];
nx = x + dx[i];
if (0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] == '.') {
c[ny][nx] = '#';
ret.eb(mp(ny, nx));
dp.eb(mp(ny, nx));
}
}
}
return ret;
}
int solve() {
var(int, w, h);
vec(string, c, h);
vector<pii> v[2];
int a = -1;
rep(i, 0, h) {
rep(j, 0, w) {
if (c[i][j] == '.') {
v[++a] = f(c, i, j, h, w);
}
}
}
int ans = 100;
each(A, v[0]) {
each(B, v[1]) {
chmin(ans, abs(A.fi - B.fi) + abs(A.se - B.se) - 1);
}
}
return ans;
}
int main() {
print(solve());
return 0;
}