結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2016-03-02 12:21:04 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 1,598 bytes | 
| コンパイル時間 | 859 ms | 
| コンパイル使用メモリ | 89,020 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-13 10:49:22 | 
| 合計ジャッジ時間 | 1,511 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
/* -*- coding: utf-8 -*-
 *
 * 13.cc: No.13 囲みたい! - 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_H = 100;
const int MAX_W = 100;
const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};
/* typedef */
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
struct Stat {
  int x, y, px, py;
  Stat() {}
  Stat(int _x, int _y, int _px, int _py): x(_x), y(_y), px(_px), py(_py) {}
};
/* global variables */
int ms[MAX_H][MAX_W];
bool used[MAX_H][MAX_W];
/* subroutines */
/* main */
int main() {
  int w, h;
  cin >> w >> h;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) cin >> ms[y][x];
  for (int y0 = 0; y0 < h; y0++)
    for (int x0 = 0; x0 < w; x0++)
      if (! used[y0][x0]) {
	int m = ms[y0][x0];
	used[y0][x0] = true;
	queue<Stat> q;
	q.push(Stat(x0, y0, -1, -1));
	while (! q.empty()) {
	  Stat u = q.front(); q.pop();
	  for (int di = 0; di < 4; di++) {
	    int vx = u.x + dxs[di], vy = u.y + dys[di];
	    if ((vx != u.px || vy != u.py) &&
		vx >= 0 && vx < w && vy >= 0 && vy < h &&
		ms[vy][vx] == m) {
	      if (used[vy][vx]) {
		puts("possible");
		return 0;
	      }
	      used[vy][vx] = true;
	      q.push(Stat(vx, vy, u.x, u.y));
	    }
	  }
	}
      }
  puts("impossible");
  return 0;
}
            
            
            
        