結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-06-11 02:07:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,585 ms / 6,000 ms |
コード長 | 935 bytes |
コンパイル時間 | 1,024 ms |
コンパイル使用メモリ | 74,752 KB |
実行使用メモリ | 38,656 KB |
最終ジャッジ日時 | 2024-11-08 07:45:33 |
合計ジャッジ時間 | 13,123 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <iostream> #include <queue> using namespace std; const int dy[] = {1, 0, -1, 0}, dx[] = {0, 1, 0, -1}; int main(){ int H,W, res=0; int A[3001][3001]; cin >> H >> W; for(int j=0; j<H; j++) for(int i=0; i<W;i++) cin >> A[j][i]; for(int j=0;j<H;j++){ for(int i=0;i<W;i++){ if(A[j][i]==0) continue; queue<pair<int, int>> que; que.push(make_pair(j, i)); A[j][i]=0; res++; while(!que.empty()){ int y= que.front().first, x = que.front().second; que.pop(); for(int k=0; k<4; k++){ int ny = y+dy[k], nx = x+dx[k]; if (!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue; if (A[ny][nx]) { A[ny][nx] = 0; que.push(make_pair(ny, nx)); } } } } } cout << res << endl; }