結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-09-16 04:46:26 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 5 ms / 5,000 ms | 
| コード長 | 1,051 bytes | 
| コンパイル時間 | 1,907 ms | 
| コンパイル使用メモリ | 173,864 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-22 03:01:16 | 
| 合計ジャッジ時間 | 2,087 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
vector<int> G[10000];
vector<bool> color(10000,false);
vector<P> ways={{1,0},{0,1},{-1,0},{0,-1}};
bool dfs(int v,int p=-1){
   if(p==-1&&color[v])return false;
   if(color[v])return true;
   color[v]=true;
   bool res=false;
   for (auto &&i : G[v]){
      if (i==p)continue;
      res|=dfs(i,v);
   }
   return res;
}
int main() {
   int M[102][102];
   rep(i,102)M[i][0]=-1;
   rep(i,102)M[0][i]=-1;
   int W,H;cin>>W>>H;
   rep(i,102)M[H+1][i]=-1;
   rep(i,102)M[i][W+1]=-1;
   rep(i,H){
      rep(j,W){
         cin>>M[i+1][j+1];
      }
   }
   rep(i,H){
      rep(j,W){
         for (auto &&way : ways){
            int i_=i+way.first,j_=j+way.second;
            if(M[i+1][j+1]==M[i_+1][j_+1]){
               G[i*W+j].push_back(i_*W+j_);
            }
         }
      }
   }
   rep(i,H*W){
      if(dfs(i)){
         cout<<"possible"<<endl;
         return 0;
      }
   }
   cout<<"impossible"<<endl;
}
            
            
            
        