結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-06-09 17:34:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,328 bytes |
コンパイル時間 | 6,616 ms |
コンパイル使用メモリ | 125,848 KB |
最終ジャッジ日時 | 2025-01-05 11:49:46 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 MLE * 2 |
ソースコード
#include<iostream> #include<iomanip> #include<math.h> #include<vector> #include<algorithm> #include<set> #include<map> #include<unordered_map> #include<queue> #include<stack> #include<string> #include<bitset> #include<random> #include<time.h> #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-7 #define REP(i,m) for(long long i=0; i<(ll)m; i++) #define FOR(i,n,m) for(long long i=n; i<(ll)m; i++) #define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; } #define ALL(v) v.begin(),v.end() #define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef long double ld; ll h,w; vector<vector<bool>> a; void dfs(P pos) { a[pos.first][pos.second]=false; ll dx[]={1,0,-1,0}; ll dy[]={0,1,0,-1}; REP(i,4) { ll nx=pos.first+dx[i]; ll ny=pos.second+dy[i]; if(nx>=0&&nx<h&&ny>=0&&ny<w&&a[nx][ny]) dfs(P(nx,ny)); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>h>>w; a.resize(h,vector<bool>(w)); REP(i,h) REP(j,w) { ll hoge; cin>>hoge; if(hoge) a[i][j]=true; else a[i][j]=false; } ll sum=0; REP(i,h) REP(j,w) { if(a[i][j]) { sum++; dfs(P(i,j)); } } cout<<sum<<endl; }