結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2016-02-19 22:33:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,749 bytes |
| コンパイル時間 | 703 ms |
| コンパイル使用メモリ | 77,100 KB |
| 実行使用メモリ | 814,580 KB |
| 最終ジャッジ日時 | 2024-09-22 12:22:36 |
| 合計ジャッジ時間 | 4,975 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | MLE * 1 -- * 15 |
ソースコード
#include <queue>
#include <algorithm>
#include <vector>
#include <iostream>
#include <numeric>
#include <tuple>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define ALL(container) (container).begin(), (container).end()
pii shifts[] = {{1,0},{0,1},{-1,0},{0,-1}};
int f[200][200];
int visit[200][200];
vector<pii> vs[3];
int main(int argc, char *argv[]){
ios::sync_with_stdio(false);
int w,h;
cin >> w >> h;
REP(i, 200) REP(j, 200) f[i][j] = 0;
REP(i, h)
{
string s;
cin >> s;
REP(j, w)
{
if(s[j] == '.')
{
f[i + 1][j + 1] = -1;
}
}
}
int id = 1;
REP(i, h) REP(j, w)
{
int sh = i + 1;
int sw = j + 1;
if(f[sh][sw] >= 0)
{
continue;
}
queue<tiii> q;
q.push(make_tuple(sw,sh, id));
vs[id].emplace_back(sw,sh);
while(!q.empty())
{
const auto t = q.front();
q.pop();
for(int s = 0;s < 4;s++)
{
auto x = get<0>(t) + shifts[s].first;
auto y = get<1>(t) + shifts[s].second;
if(f[y][x] >= 0)
{
continue;
}
f[y][x] = id;
vs[id].emplace_back(x,y);
q.push(make_tuple(x,y,id));
}
}
id++;
}
{
REP(i, 200) REP(j, 200) visit[i][j] = 0;
queue<tiii> q;
for(int i = 0;i < vs[1].size();i++)
{
auto t = vs[1][i];
for(int s = 0;s < 4;s++)
{
auto x = get<0>(t) + shifts[s].first;
auto y = get<1>(t) + shifts[s].second;
if(f[y][x] == 0)
{
q.push(make_tuple(x,y,1));
visit[y][x] = true;
}
}
}
while(!q.empty())
{
const auto t = q.front();
q.pop();
auto c = get<2>(t);
for(int s = 0;s < 4;s++)
{
auto x = get<0>(t) + shifts[s].first;
auto y = get<1>(t) + shifts[s].second;
if(f[y][x] == 0)
{
if(!visit[y][x])
{
q.push(make_tuple(x,y,c+1));
}
}
if(f[y][x] == 2)
{
cout << c << endl;
return 0;
}
}
}
}
return 0;
}
nanophoto12