結果

問題 No.157 2つの空洞
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2015-02-25 19:48:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 1,877 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 91,140 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-06 04:38:19
合計ジャッジ時間 3,361 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
4,380 KB
testcase_01 AC 76 ms
4,376 KB
testcase_02 AC 77 ms
4,376 KB
testcase_03 AC 77 ms
4,380 KB
testcase_04 AC 77 ms
4,380 KB
testcase_05 AC 77 ms
4,380 KB
testcase_06 AC 77 ms
4,380 KB
testcase_07 AC 77 ms
4,380 KB
testcase_08 AC 77 ms
4,376 KB
testcase_09 AC 76 ms
4,380 KB
testcase_10 AC 76 ms
4,380 KB
testcase_11 AC 77 ms
4,376 KB
testcase_12 AC 77 ms
4,376 KB
testcase_13 AC 78 ms
4,380 KB
testcase_14 AC 77 ms
4,376 KB
testcase_15 AC 77 ms
4,376 KB
testcase_16 AC 78 ms
4,380 KB
testcase_17 AC 77 ms
4,500 KB
testcase_18 AC 77 ms
4,380 KB
testcase_19 AC 77 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

#define V 400

int m[V][V];

int main(){
  int dx[4]={-1,0,0,1};
  int dy[4]={0,1,-1,0};
  int w,h;
  cin>>w>>h;
  vector<string> v;
  rep(i,0,h){
    string s;
    cin>>s;
    v.pb(s);
  }
  for(int i = 0; i < V; i++){
    for(int r = 0; r < V; r++){
      if(i == r){
        m[i][i] = 0;
      }
      else{
        m[i][r] = 10000;
      }
    }
  }
  rep(y,1,h-1){
    rep(x,1,w-1){
      rep(i,0,4){
        if(v[y][x]=='.'&&v[y+dy[i]][x+dx[i]]=='.'){
          m[w*y+x][w*(y+dy[i])+(x+dx[i])]=0;
          m[w*(y+dy[i])+(x+dx[i])][w*y+x]=0;
        }
        else{
          m[w*y+x][w*(y+dy[i])+(x+dx[i])]=1;
          m[w*(y+dy[i])+(x+dx[i])][w*y+x]=1;
        }
      }
    }
  }
  for(int k = 0; k < V; k++){
    for(int i = 0; i < V; i++){
      for(int j = 0; j < V; j++){
        if(m[i][j] > m[i][k] + m[k][j]){
          m[i][j] = m[i][k] + m[k][j];
        }
      }
    }
  }
  int mn = 10000;
  rep(y1,1,h-1){
    rep(x1,1,w-1){
      rep(y2,1,h-1){
        rep(x2,1,w-1){
          if(v[y1][x1]=='.'&&v[y2][x2]=='.'){
            if(m[w*y1+x1][w*y2+x2]!=0){
              mn = min(mn,m[w*y1+x1][w*y2+x2]-1);
            }
          }
        }
      }
    }
  }
  cout << mn << endl;
  return 0;
}

/*
ワーシャルフロイド解。
*/
0