結果

問題 No.13 囲みたい!
ユーザー SakaTakuSakaTaku
提出日時 2020-09-16 04:46:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,051 bytes
コンパイル時間 1,857 ms
コンパイル使用メモリ 171,976 KB
実行使用メモリ 4,408 KB
最終ジャッジ日時 2023-09-04 03:19:08
合計ジャッジ時間 2,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0