結果

問題 No.86 TVザッピング(2)
ユーザー imgry22imgry22
提出日時 2014-12-21 18:12:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 2,219 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 145,516 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 14:59:06
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;

#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, n)    for(int (i)=1; (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, n)    for(int (i)=(n); (i)>=1; (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define EACH(v)       (v).begin(), (v).end()
#define minup(m, x)   (m=min(m, x))
#define maxup(m, x)   (m=max(m, x))
#define mp            make_pair
#define pb            push_back

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

#define MAX_M 100
#define MAX_N 100

inline bool check(int x, int y);
bool dfs(int px, int py, int hx, int hy, int cnt, int cntRight, int cntLeft);

int n, m;
char a[MAX_N][MAX_M];
int cnt;
bool used[MAX_N][MAX_M];
int sx, sy;

int main()
{
  cin >> n >> m;
  rep(i, n) rep(j, m){
    cin >> a[i][j];
    if(a[i][j] == '.'){
      sx = i;
      sy = j;
      cnt += 1;
    }
  }

  bool flag = false;
  used[sx][sy] = true;
  if(check(sx+1, sy  ))  flag |= dfs(sx, sy, sx+1, sy,   cnt, 0, 0);
  if(check(sx,   sy+1))  flag |= dfs(sx, sy, sx,   sy+1, cnt, 0, 0);
  if(check(sx-1, sy  ))  flag |= dfs(sx, sy, sx-1, sy,   cnt, 0, 0);

  puts(flag ? "YES" : "NO");

  return 0;
}

inline bool check(int x, int y)
{
  return 0<=x&&x<n && 0<=y&&y<m;
}

bool dfs(int px, int py, int hx, int hy, int cnt, int cntRight, int cntLeft)
{
  int nx, ny;

  used[hx][hy] = true;
  rep(i, 3){
    if(i == 0){
      nx = hx + hx - px;
      ny = hy + hy - py;
    }
    if(i == 1){
      if(cntLeft+1 > 6) return false;
      nx = hx - hy + py;
      ny = hy + hx - px;
    }
    if(i == 2 && cntRight == 0){
      nx = hx + hy - py;
      ny = hy - hx + px;
      cntRight = 1;
    }

    if(!check(nx, ny)) continue;
    if(a[nx][ny] == '#') continue;
    if((mp(nx, ny) == mp(sx, sy)) && (cnt == 2)) return true;
    if(used[nx][ny]) continue;

    if(dfs(hx, hy, nx, ny, cnt-1, cntRight, cntLeft + i%2)) return true;
    if(i == 2) cntRight = 0;
  }

  used[hx][hy] = false;
  return false;
}
0