結果
問題 | No.697 池の数はいくつか |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2018-06-09 18:32:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 719 ms / 6,000 ms |
コード長 | 2,135 bytes |
コンパイル時間 | 1,690 ms |
コンパイル使用メモリ | 171,192 KB |
実行使用メモリ | 38,896 KB |
最終ジャッジ日時 | 2024-04-25 19:54:01 |
合計ジャッジ時間 | 8,177 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 81 ms
16,664 KB |
testcase_25 | AC | 80 ms
16,664 KB |
testcase_26 | AC | 85 ms
16,444 KB |
testcase_27 | AC | 82 ms
15,920 KB |
testcase_28 | AC | 78 ms
15,260 KB |
testcase_29 | AC | 684 ms
38,780 KB |
testcase_30 | AC | 719 ms
38,756 KB |
testcase_31 | AC | 686 ms
38,896 KB |
testcase_32 | AC | 712 ms
38,744 KB |
testcase_33 | AC | 698 ms
38,672 KB |
testcase_34 | AC | 708 ms
38,732 KB |
ソースコード
#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; }