結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
👑 kmjp
|
| 提出日時 | 2018-06-10 16:28:16 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,085 ms / 6,000 ms |
| コード長 | 1,422 bytes |
| 記録 | |
| コンパイル時間 | 1,824 ms |
| コンパイル使用メモリ | 164,464 KB |
| 実行使用メモリ | 110,076 KB |
| 最終ジャッジ日時 | 2024-11-08 07:45:18 |
| 合計ジャッジ時間 | 13,389 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
template<int um> class UF {
public:
vector<int> par,rank;
UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++) par.push_back(i);}
int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
int operator()(int x,int y) {
if((x=operator[](x))==(y=operator[](y))) return x;
if(rank[x]>rank[y]) return par[x]=y;
rank[x]+=rank[x]==rank[y]; return par[y]=x;
}
};
UF<3020*3020> uf;
int H,W;
int A[3030][3030];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>H>>W;
FOR(y,H) FOR(x,W) cin>>A[y][x];
FOR(y,H) FOR(x,W) if(A[y][x]) {
if(y &&A[y-1][x]) uf(y*3000+x,(y-1)*3000+x);
if(x &&A[y][x-1]) uf(y*3000+x,y*3000+x-1);
}
int ret=0;
FOR(y,H) FOR(x,W) if(A[y][x] && uf[y*3000+x]==y*3000+x) ret++;
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
kmjp