結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2018-08-13 14:19:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 990 ms / 6,000 ms |
コード長 | 1,129 bytes |
コンパイル時間 | 1,521 ms |
コンパイル使用メモリ | 77,416 KB |
実行使用メモリ | 94,404 KB |
最終ジャッジ日時 | 2024-11-08 08:02:36 |
合計ジャッジ時間 | 9,671 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include<cstdio> #include<queue> #include<utility> #include<cstring> #include<stack> #include<algorithm> #include<cmath> #include<iostream> #include<map> #define MAX_N 100001 #define INF_INT 2147483647 #define INF_LL 9223372036854775807 #define REP(i,n) for(int i=0;i<(int)(n);i++) int dx[4] = {1,0,0,-1}; int dy[4] = {0,1,-1,0}; using namespace std; typedef long long int ll; typedef pair<ll,ll> P; int main() { int N,H,W,res=0; char pond[3010][3010]; bool visited[3010][3010]; REP(i,3010)REP(j,3010)visited[i][j] = false; cin >> H >> W; REP(i,H)REP(j,W)cin >> pond[i][j]; stack<P> stk; REP(i,H)REP(j,W){ if(pond[i][j] == '1'){ stk.push(P(j,i)); while(!stk.empty()){ P p = stk.top();stk.pop(); pond[p.second][p.first] = '0'; REP(i,4){ int x = p.first+dx[i],y=p.second+dy[i]; if(x < W && 0 <= x && y < H && y >= 0){ if(visited[y][x] == false && pond[y][x] == '1'){ stk.push(P(x,y)); visited[y][x] = true; } } } } res++; } } cout << res << endl; return 0; }