結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2020-03-09 02:37:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 778 ms / 6,000 ms |
コード長 | 1,418 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 172,056 KB |
実行使用メモリ | 38,656 KB |
最終ジャッジ日時 | 2024-11-08 08:36:13 |
合計ジャッジ時間 | 8,967 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { ios_base::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; int a[h+2][w+2]; rep(i,h+2){ rep(j,w+2){ if(i == 0 || i == h + 1 || j == 0 || j == w + 1){ a[i][j] = 0; }else{ cin >> a[i][j]; } } } int ans = 2; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; rep(i,h+2){ rep(j,w+2){ if(a[i][j] == 1){ queue<P> que; a[i][j] = ans; que.push(P(i, j)); while(que.size()){ int x = que.front().first; int y = que.front().second; que.pop(); rep(k,4){ if(a[x+dx[k]][y+dy[k]] == 1){ a[x+dx[k]][y+dy[k]] = ans; que.push(P(x+dx[k], y+dy[k])); } } } ans++; } } } ans -= 2; cout << ans << endl; return 0; }