結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2019-04-30 11:11:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 947 ms / 6,000 ms |
コード長 | 1,576 bytes |
コンパイル時間 | 1,135 ms |
コンパイル使用メモリ | 102,572 KB |
実行使用メモリ | 48,128 KB |
最終ジャッジ日時 | 2024-11-08 08:14:08 |
合計ジャッジ時間 | 9,606 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include <cstdlib> #include <math.h> #include <cmath> #include<cctype> #include<string> #include<set> #include<iomanip> #include <map> #include<algorithm> #include <functional> #include<vector> #include<climits> #include<stack> #include<queue> #include <deque> #include <climits> #include <typeinfo> #include <utility> #define all(x) (x).begin(),(x).end() #define rep(i,m,n) for(int i = m;i < n;++i) #define pb push_back #define fore(i,a) for(auto &i:a) #define rrep(i,m,n) for(int i = m;i >= n;--i) #define INF INT_MAX/2 using namespace std; using ll = long long; using R = double; using Data = pair<ll, vector<int>>; const ll MOD = 1e9 + 7; const ll inf = 1LL << 50; struct edge { ll from; ll to; ll cost; }; vector<vector<char>>mp(3030,vector<char>(3030)); int used[3030][3030]; int h, w; void bfs(int x, int y) { used[y][x] = 1; queue<pair<int, int>>q; q.push({x,y}); while (!q.empty()) { auto now = q.front(); q.pop(); int xnow = now.first; int ynow = now.second; int dx[4] = { -1,0,1,0 }; int dy[4] = { 0,-1,0,1 }; rep(i, 0, 4) { int _x = xnow + dx[i]; int _y = ynow + dy[i]; if (0 <= _x && _x <= w - 1 && 0 <= _y && _y <= h - 1) { if (used[_y][_x] == 0 && mp[_y][_x] == '1') { q.push({ _x,_y }); used[_y][_x] = 1; } } } } return; } int main() { cin >> h >> w; rep(i, 0, h)rep(j,0,w)cin >> mp[i][j]; int ans = 0; rep(i, 0, h)rep(j,0,w){ if (mp[i][j] == '1' && used[i][j] == 0) { bfs(j,i); ans++; } } cout << ans << endl; return 0; }