結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2021-01-10 20:14:58 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,019 bytes |
コンパイル時間 | 6,169 ms |
コンパイル使用メモリ | 138,872 KB |
実行使用メモリ | 741,608 KB |
最終ジャッジ日時 | 2024-11-25 16:53:08 |
合計ジャッジ時間 | 16,780 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 MLE * 2 |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_H = 3000; const int MAX_W = 3000; const int DY[4] = {-1, 0, 1, 0}; const int DX[4] = {0, 1, 0, -1}; int H, W; int A[MAX_H][MAX_W]; void f(int y, int x) { assert(A[y][x] == 1); A[y][x] = 0; for (int i = 0; i < 4; ++i) { int ny = y + DY[i]; int nx = x + DX[i]; if (ny < 0 || nx < 0 || H <= ny || W <= nx) continue; if (A[ny][nx] == 0) continue; f(ny, nx); } } int main() { cin >> H >> W; fprintf(stderr, "H: %d, W: %d\n", H, W); for (int y = 0; y < H; ++y) { for (int x = 0; x < W; ++x) { cin >> A[y][x]; } } int ans = 0; for (int y = 0; y < H; ++y) { for (int x = 0; x < W; ++x) { if (A[y][x] == 0) continue; ++ans; f(y, x); } } cout << ans << endl; return 0; }