結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-06-25 23:55:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 851 bytes |
コンパイル時間 | 1,997 ms |
コンパイル使用メモリ | 165,312 KB |
実行使用メモリ | 814,636 KB |
最終ジャッジ日時 | 2024-11-25 13:54:35 |
合計ジャッジ時間 | 18,978 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | AC * 18 RE * 12 MLE * 2 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ cin.tie(0); ios::sync_with_stdio(false); int H,W; cin >> H >> W; int A[3000][3000]; int ans = 0; for(int i = 0;i < H;i++){ for(int j = 0;j < W; j++){ cin >> A[i][j]; } } for(int i = 0;i < H;i++){ for(int j = 0;j < W; j++){ if(A[i][j]==0)continue; //0なら処理を飛ばす queue<pair<int,int>> q; q.push({i,j}); //queueに座標を保存 while(!q.empty()){ int X = q.front().first; int Y = q.front().second; q.pop(); if(A[X][Y] == 0)continue; //0なら処理を飛ばす A[X][Y] = 0; //今の要素を0にする; q.push({X + 1,Y}); //queueに周りの座標を格納 q.push({X - 1,Y}); q.push({X,Y + 1}); q.push({X,Y - 1}); } ans++; } } cout << ans << endl; return 0; }