結果

問題 No.13 囲みたい!
ユーザー kk
提出日時 2021-02-19 22:41:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,049 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 199,636 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-15 03:33:07
合計ジャッジ時間 9,807 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 4 ms
4,352 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int w, h;
int bd[128][128];
int vis[128][128];
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

bool dfs(int y, int x, int py, int px) {
  if (vis[y][x] == -1) {
    return true;
  }
  vis[y][x] = -1;
  bool ret = false;
  for (int k = 0; k < 4; k++) {
    int y2 = y + dy[k];
    int x2 = x + dx[k];
    if (x2 < 0 || x2 >= w) continue;
    if (y2 < 0 || y2 >= h) continue;
    if (y2 == py && x2 == px) continue;
    if (bd[y2][x2] != bd[y][x]) continue;
    ret |= dfs(y2, x2, y, x);
  }
  vis[y][x] = 1;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> w >> h;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> bd[i][j];

  bool ck = false;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vis[i][j]) continue;
      ck |= dfs(i, j, -1, -1);
    }
  }
  

  if (ck)
    cout << "possible" << endl;
  else
    cout << "impossible" << endl;
  
  return 0;
}
0