結果

問題 No.86 TVザッピング(2)
ユーザー tnakao0123tnakao0123
提出日時 2016-03-10 23:25:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 858 ms / 5,000 ms
コード長 1,676 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 83,116 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 15:02:14
合計ジャッジ時間 2,900 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 858 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 72 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 86.cc: No.86 TVザッピング(2) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 100;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

/* typedef */

/* global variables */

int n, m, cn;
string as[MAX_N];
bool used[MAX_N][MAX_M];

/* subroutines */

bool check(int sx, int sy, int di) {
  memset(used, false, sizeof(used));

  int x = sx, y = sy, c = 0;

  for (;;) {
    used[y][x] = true;
    c++;

    int d;
    for (d = 0; d < 2; d++) {
      int di0 = (di + d) & 3;
      int x0 = x + dxs[di0], y0 = y + dys[di0];
      if (x0 >= 0 && x0 < m && y0 >= 0 && y0 < n && as[y0][x0] == '.') {
	if (x0 == sx && y0 == sy) {
	  //printf("  c=%d, cn=%d\n", c, cn);
	  return (c == cn);
	}
	if (! used[y0][x0]) {
	  x = x0, y = y0, di = di0;
	  break;
	}
      }
    }
    if (d >= 2) return false;
  }
  return false;
}

/* main */

int main() {
  cin >> n >> m;
  for (int y = 0; y < n; y++) {
    cin >> as[y];
    for (int x = 0; x < m; x++)
      if (as[y][x] == '.') cn++;
  }

  for (int sy = 0; sy < n; sy++)
    for (int sx = 0; sx < m; sx++)
      for (int di = 0; di < 4; di++)
	if (as[sy][sx] == '.') {
	  bool ans = check(sx, sy, di);
	  //printf("%d,%d,%d = %d\n", sx, sy, di, ans);
	  if (ans) {
	    puts("YES");
	    return 0;
	  }
	}

  puts("NO");
  return 0;
}
0