結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2021-01-01 17:59:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 997 bytes |
コンパイル時間 | 809 ms |
コンパイル使用メモリ | 87,052 KB |
実行使用メモリ | 741,632 KB |
最終ジャッジ日時 | 2024-11-25 16:45:04 |
合計ジャッジ時間 | 14,238 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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)); void dfs(int y, int x) { a[y][x] = 2; 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] == 1) { 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] == 1) { ans++; dfs(i, j); } } } cout << ans << endl; return 0; }