結果
| 問題 |
No.697 池の数はいくつか
|
| ユーザー |
|
| 提出日時 | 2021-01-01 17:52:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,090 bytes |
| コンパイル時間 | 1,575 ms |
| コンパイル使用メモリ | 92,308 KB |
| 実行使用メモリ | 743,168 KB |
| 最終ジャッジ日時 | 2024-11-25 16:45:37 |
| 合計ジャッジ時間 | 16,384 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 MLE * 2 |
ソースコード
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 1000000007
int h, w;
vector<vector<int> > a(3000, vector<int>(3000));
vector<vector<bool> > visit(3000, vector<bool>(3000, false));
void dfs(int y, int x) {
visit[y][x] = true;
for (int i = -1; i <= 1; ++i) {
for (int j = -1; j <= 1; ++j) {
if (i * i + j * j == 1) {
int ny = y + i, nx = x + j;
if (0 <= ny && ny < h && 0 <= nx && nx < w) {
if (a[ny][nx] && !visit[ny][nx]) {
dfs(ny, nx);
}
}
}
}
}
}
int main() {
cin >> h >> w;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> a[i][j];
}
}
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (a[i][j] && !visit[i][j]) {
ans++;
dfs(i, j);
}
}
}
cout << ans << endl;
return 0;
}