結果

問題 No.697 池の数はいくつか
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2018-06-09 17:56:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,626 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 95,868 KB
実行使用メモリ 814,164 KB
最終ジャッジ日時 2024-05-04 05:18:06
合計ジャッジ時間 6,161 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
6,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
6,940 KB
testcase_23 WA -
testcase_24 MLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

char d[10001][10001];

int main() {
  short h,w;
  cin>>h>>w;
  rep(y,0,h){
    rep(x,0,w){
      char a;
      cin>>a;
      d[y][x] = a;
    }
  }
  int ans = 0;
  short dy[4] = {0,0,-1,1};
  short dx[4] = {-1,1,0,0};
  rep(y,0,h){
    rep(x,0,w){
      if(d[y][x]==0)continue;
      ans++;
      queue<short> q1;
      queue<short> q2;
      q1.push(y);
      q2.push(x);
      while(!q1.empty()){
        short y1 = q1.front();q1.pop();
        short x1 = q2.front();q2.pop();
        d[y1][x1] = 0;
        rep(i,0,4){
          short y2 = y1 + dy[i];
          short x2 = x1 + dx[i];
          if(y2<0)continue;
          if(y2>=h)continue;
          if(x2<0)continue;
          if(x2>=w)continue;
          if(d[y2][x2]==0)continue;
          q1.push(y2);
          q2.push(x2);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0