結果

問題 No.13 囲みたい!
ユーザー SakaTakuSakaTaku
提出日時 2020-09-16 04:30:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 982 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 170,728 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 03:18:41
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 4 ms
4,376 KB
testcase_07 WA -
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,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 1 ms
4,376 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;
   for (auto &&i : G[v]){
      if (i==p)continue;
      return dfs(i,v);
   }
   return false;
}
int main() {
   int M[101][101];
   rep(i,101)M[i][0]=-1;
   rep(i,101)M[0][i]=-1;
   int W,H;cin>>W>>H;
   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