結果
問題 | No.697 池の数はいくつか |
ユーザー |
![]() |
提出日時 | 2018-06-09 18:32:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 765 ms / 6,000 ms |
コード長 | 2,135 bytes |
コンパイル時間 | 1,694 ms |
コンパイル使用メモリ | 172,568 KB |
実行使用メモリ | 38,784 KB |
最終ジャッジ日時 | 2024-11-08 07:36:25 |
合計ジャッジ時間 | 8,734 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int H, W, A[3010][3010]; int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 }; //--------------------------------------------------------------------------------------------------- void _main() { cin >> H >> W; rep(y, 0, H) rep(x, 0, W) cin >> A[y][x]; int ans = 0; rep(sy, 0, H) rep(sx, 0, W) if (A[sy][sx] == 1) { ans++; queue<pair<int, int>> que; que.push({ sx, sy }); A[sy][sx] = 0; while (!que.empty()) { int x = que.front().first; int y = que.front().second; que.pop(); rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (0 <= xx and xx < W and 0 <= yy and yy < H) if (A[yy][xx] == 1) { que.push({ xx, yy }); A[yy][xx] = 0; } } } } cout << ans << endl; }