結果
問題 | No.13 囲みたい! |
ユーザー | momoyuu |
提出日時 | 2023-03-16 15:11:10 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,522 bytes |
コンパイル時間 | 2,921 ms |
コンパイル使用メモリ | 254,112 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-18 09:21:24 |
合計ジャッジ時間 | 3,803 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int w,h; cin>>w>>h; vector<vector<int> >m(h,vector<int>(w)); for(int i = 0;i<h;i++) for(int j = 0;j<w;j++) cin>>m[i][j]; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; deque<pair<pair<int,int>,pair<int,int> > > que; vector<vector<int> > vis(h,vector<int>(w,0)); bool fn = false; for(int i = 0;i<h;i++){ for(int j = 0;j<w;j++){ if(vis[i][j]) continue; int now = m[i][j]; que.push_back(make_pair(make_pair(i,j),make_pair(-1,-1))); while(que.size()){ int ni = que.front().first.first; int nj = que.front().first.second; int pi = que.front().second.first; int pj = que.front().second.second; que.pop_front(); for(int k = 0;k<4;k++){ int nni = ni + dx[k]; int nnj = nj + dy[k]; if(nni<0||nni>=h||nnj<0||nnj>=w) continue; if(nni==pi&&nnj==pj) continue; if(m[ni][nj]!=m[nni][nnj]) continue; if(vis[nni][nnj]){ fn = true; }else{ vis[nni][nnj] = 1; que.push_back(make_pair(make_pair(nni,nnj),make_pair(ni,nj))); } } } } } if(fn) cout<<"possible\n"; else cout<<"impossible\n"; }