結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-06-09 16:41:36 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,665 ms / 6,000 ms |
コード長 | 1,186 bytes |
コンパイル時間 | 765 ms |
コンパイル使用メモリ | 67,632 KB |
実行使用メモリ | 24,192 KB |
最終ジャッジ日時 | 2024-11-08 07:33:28 |
合計ジャッジ時間 | 13,474 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream> #include <algorithm> #include <stack> #include <queue> #include <vector> using namespace std; int H,W; bool A[10000][10000]; int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0}; int solve(int y,int x){ if (!A[y][x]) { return 0; } A[y][x] = false; queue<pair<int,int> > q; q.push(make_pair(y,x)); while(!q.empty()) { int c_y = q.front().first; int c_x = q.front().second; q.pop(); A[c_y][c_x] = false; for (int k = 0; k < 4; k++) { int ny = c_y + dy[k]; int nx = c_x + dx[k]; if (0 <= ny && ny < H && 0 <= nx && nx < W && A[ny][nx]) { // solve(ny, nx); A[ny][nx] = false; q.push(make_pair(ny, nx)); } } } return 1; } int main(){ cin >> H >> W; for(int i = 0;i < H;i++) { for(int j = 0;j < W;j++) { cin >> A[i][j]; } } int res = 0; for(int i = 0;i < H;i++) { for(int j = 0;j < W;j++) { res += solve(i,j); } } cout << res << endl; return 0; }