結果

問題 No.697 池の数はいくつか
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2018-06-09 17:41:46
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,508 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 96,180 KB
実行使用メモリ 814,720 KB
最終ジャッジ日時 2024-05-04 05:15:35
合計ジャッジ時間 13,716 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
101,172 KB
testcase_01 AC 25 ms
101,288 KB
testcase_02 AC 25 ms
101,140 KB
testcase_03 AC 25 ms
101,168 KB
testcase_04 AC 25 ms
101,184 KB
testcase_05 AC 26 ms
101,192 KB
testcase_06 AC 25 ms
101,132 KB
testcase_07 AC 25 ms
101,032 KB
testcase_08 AC 25 ms
101,332 KB
testcase_09 AC 26 ms
101,260 KB
testcase_10 AC 25 ms
101,156 KB
testcase_11 AC 25 ms
101,084 KB
testcase_12 AC 25 ms
101,168 KB
testcase_13 AC 24 ms
101,312 KB
testcase_14 AC 25 ms
101,144 KB
testcase_15 AC 25 ms
101,372 KB
testcase_16 AC 25 ms
101,208 KB
testcase_17 AC 25 ms
101,176 KB
testcase_18 AC 26 ms
101,188 KB
testcase_19 AC 26 ms
101,184 KB
testcase_20 AC 24 ms
101,324 KB
testcase_21 AC 25 ms
101,124 KB
testcase_22 AC 25 ms
101,308 KB
testcase_23 AC 25 ms
101,136 KB
testcase_24 AC 574 ms
106,012 KB
testcase_25 AC 1,175 ms
139,100 KB
testcase_26 AC 1,767 ms
220,052 KB
testcase_27 AC 2,587 ms
161,164 KB
testcase_28 AC 901 ms
113,712 KB
testcase_29 MLE -
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[10010][10010];

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