結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-10-21 18:27:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,765 ms / 6,000 ms |
コード長 | 955 bytes |
コンパイル時間 | 2,342 ms |
コンパイル使用メモリ | 163,044 KB |
実行使用メモリ | 111,984 KB |
最終ジャッジ日時 | 2024-11-08 08:08:02 |
合計ジャッジ時間 | 15,408 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1000000007; const int MAX_N = 3010; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) int field[MAX_N][MAX_N]; int h, w; typedef pair<int, int> P; void dfs(int x, int y){ stack<P> s; s.push(P(x, y)); while(s.size()){ P p = s.top(); s.pop(); field[p.first][p.second] = 0; for (int i = 0; i < 4; i++){ int nx = p.first + dx[i]; int ny = p.second + dy[i]; if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny]){ s.push(P(nx, ny)); } } } } int main(){ cin >> h >> w; int i, j; REP(i, h) REP(j, w) cin >> field[i][j]; int ans = 0; REP(i, h) REP(j, w){ if (field[i][j]){ dfs(i, j); ans++; } } cout << ans << endl; return 0; }