結果
問題 | No.13 囲みたい! |
ユーザー |
![]() |
提出日時 | 2019-10-03 16:00:01 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,507 bytes |
コンパイル時間 | 2,514 ms |
コンパイル使用メモリ | 106,388 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-03 06:28:30 |
合計ジャッジ時間 | 1,899 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 6 |
ソースコード
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; struct uf { private: vector<int> par,ran; public: vector<int> edge,size; void init(int n) { par.resize(n,0); ran.resize(n,0); size.resize(n,1); edge.resize(n,0); rep(i,n) { par[i]=i; } } int find(int x) { if (par[x]==x)return x; else return par[x]=find(par[x]); } void unite(int x, int y) { x=find(x),y=find(y); if (x==y){ edge[x]++; return; } if (ran[x]<ran[y]) { par[x]=y; size[y]+=size[x]; edge[y]++; } else { par[y]=x; size[x]+=size[y]; edge[x]++; if (ran[x]==ran[y])ran[x]++; } } bool same(int x,int y) { return find(x)==find(y); } }; int h,w; int m[110][110]; void solve(){ cin >> w >> h; rep(i,h){ rep(j,w){ cin >> m[i][j]; } } uf u;u.init(h*w); rep(i,h){ rep(j,w-1){ if (m[i][j]==m[i][j+1]) u.unite(i*w+j,i*w+j+1); } } rep(j,w){ rep(i,h-1){ if (m[i][j]==m[i+1][j]) u.unite(i*w+j,(i+1)*w+j); } } rep(i,h){ rep(j,w){ if (u.size[u.find(i*w+j)]<=u.edge[u.find(i*w+j)]) { cout << "possible" << endl; return; } } } cout << "impossible" << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }