結果
問題 | No.697 池の数はいくつか |
ユーザー |
![]() |
提出日時 | 2018-06-23 18:32:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,777 ms / 6,000 ms |
コード長 | 742 bytes |
コンパイル時間 | 1,911 ms |
コンパイル使用メモリ | 163,692 KB |
実行使用メモリ | 39,040 KB |
最終ジャッジ日時 | 2024-11-08 07:58:44 |
合計ジャッジ時間 | 16,225 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) int H,W; int A[3030][3030]; int main(){ cin >> H >> W; rep(i,1,H){ rep(j,1,W){ cin >> A[i][j]; } } using P = pair<int,int>; int ans = 0; rep(i,1,H){ rep(j,1,W){ if(A[i][j] == 0) continue; queue<P> que; que.push({i,j}); while(!que.empty()){ int x = que.front().first; int y = que.front().second; que.pop(); if(A[x][y] == 0) continue; A[x][y] = 0; que.push({x + 1,y}); que.push({x - 1,y}); que.push({x,y + 1}); que.push({x,y - 1}); } ans++; } } cout << ans << endl; }