結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2018-06-10 22:57:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 744 bytes |
| コンパイル時間 | 719 ms |
| コンパイル使用メモリ | 65,264 KB |
| 実行使用メモリ | 741,656 KB |
| 最終ジャッジ日時 | 2024-11-25 13:15:29 |
| 合計ジャッジ時間 | 13,158 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 MLE * 2 |
ソースコード
#include <iostream>
using namespace std;
int H,W;
int A[3000][3000];
void dfs(int x, int y){
A[y][x] = 0;
int nx, ny;
nx=x; ny=y+1;
if(ny<H && A[ny][nx]==1) dfs(nx,ny);
nx=x; ny=y-1;
if(ny>=0 && A[ny][nx]==1) dfs(nx,ny);
nx=x-1; ny=y;
if(nx>=0 && A[ny][nx]==1) dfs(nx,ny);
nx=x+1; ny=y;
if(nx<W && A[ny][nx]==1) dfs(nx,ny);
}
void solve(){
int res = 0;
for(int j=0;j<H;j++){
for(int i=0;i<W;i++){
if(A[j][i]==1){
dfs(i,j);
res++;
}
}
}
cout << res << endl;
}
int main(){
cin >> H >> W;
for(int j=0; j<H; j++)
for(int i=0; i<W;i++)
cin >> A[j][i];
solve();
}