結果
| 問題 | No.697 池の数はいくつか |
| ユーザー |
|
| 提出日時 | 2018-06-10 22:50:12 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 986 bytes |
| 記録 | |
| コンパイル時間 | 722 ms |
| コンパイル使用メモリ | 65,212 KB |
| 実行使用メモリ | 741,476 KB |
| 最終ジャッジ日時 | 2024-11-25 13:15:43 |
| 合計ジャッジ時間 | 13,428 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 MLE * 2 |
ソースコード
#include <iostream>
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MAX_H 3000
#define MAX_W 3000
using namespace std;
int H,W;
int A[MAX_H][MAX_W];
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();
}