結果

問題 No.13 囲みたい!
ユーザー y_mazuny_mazun
提出日時 2015-04-24 00:30:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,057 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 51,968 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:18:18
合計ジャッジ時間 1,117 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:7:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~

ソースコード

diff #

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

#include <queue>
#include <cstdio>
#include <functional>

inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

int main(){
  const int w = getInt();
  const int h = getInt();
  vector<vector<int> > g(h, vector<int>(w));
  REP(i,h) REP(j,w) g[i][j] = getInt();

  vector<vector<int> > f(h, vector<int>(w));

  function<bool(int, int, int, int)> dfs = [&](int y, int x, int py, int px){
    if(f[y][x]) return true;
    f[y][x] = true;
    REP(i,4){
      const int xx = x + _dx[i];
      const int yy = y + _dy[i];
      if(ISIN(xx, yy, w, h) && (xx != px || yy != py) && g[y][x] == g[yy][xx])
        if(dfs(yy, xx, y, x)) return true;
    }
    return false;
  };

  bool ans = false;
  REP(i,h) REP(j,w) if(!f[i][j])
    ans |= dfs(i, j, -1, -1);

  puts(ans ? "possible" : "impossible");

  return 0;
}
0