結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-08-31 14:14:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 837 bytes |
コンパイル時間 | 1,645 ms |
コンパイル使用メモリ | 172,800 KB |
実行使用メモリ | 601,088 KB |
最終ジャッジ日時 | 2024-11-25 14:05:03 |
合計ジャッジ時間 | 14,782 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 MLE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); for (auto &aa : a) { for (auto &aaa : aa) { cin >> aaa; } } int ans = 0, dd[] = {0, 1, 0, -1, 0}; function<void(int, int)> f = [&](int x, int y) { if (a[x][y] != 1) { return; } a[x][y] = 2; for (int i = 0; i < 4; i++) { int nx = x + dd[i], ny = y + dd[i + 1]; if (0 <= nx && nx < n && 0 <= ny && ny < m) { f(nx, ny); } } }; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == 1) { f(i, j); ans++; } } } cout << ans << endl; return 0; }