結果

問題 No.348 カゴメカゴメ
ユーザー roiti46roiti46
提出日時 2016-02-26 23:53:09
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,935 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 160,880 KB
実行使用メモリ 118,376 KB
最終ジャッジ日時 2023-10-24 10:53:05
合計ジャッジ時間 4,322 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
36,292 KB
testcase_01 WA -
testcase_02 AC 59 ms
45,568 KB
testcase_03 AC 36 ms
9,000 KB
testcase_04 AC 2 ms
6,024 KB
testcase_05 AC 3 ms
8,892 KB
testcase_06 AC 2 ms
5,708 KB
testcase_07 AC 2 ms
5,696 KB
testcase_08 AC 2 ms
5,692 KB
testcase_09 AC 2 ms
5,736 KB
testcase_10 AC 3 ms
5,720 KB
testcase_11 AC 2 ms
5,724 KB
testcase_12 AC 5 ms
8,212 KB
testcase_13 AC 3 ms
6,216 KB
testcase_14 AC 2 ms
5,860 KB
testcase_15 AC 111 ms
118,376 KB
testcase_16 AC 2 ms
5,696 KB
testcase_17 AC 2 ms
5,704 KB
testcase_18 AC 3 ms
5,696 KB
testcase_19 AC 2 ms
5,696 KB
testcase_20 AC 2 ms
5,768 KB
testcase_21 AC 2 ms
5,772 KB
testcase_22 AC 2 ms
5,700 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 3 ms
6,364 KB
testcase_48 AC 3 ms
6,236 KB
testcase_49 WA -
testcase_50 AC 3 ms
6,372 KB
testcase_51 WA -
testcase_52 AC 3 ms
6,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int N, M;
char G[1005][1005];
int depth[1005][1005];
int num[1000];

bool is_inside(int x, int y) {
  return (0 <= x && x < M && 0 <= y && y < N);
}

int dfs(int x, int y) {
  G[y][x] = 'X';
  int res = 1;
  rep(i, 8) {
    int nx = x + dx[i], ny = y + dy[i];
    if (!is_inside(nx, ny)) continue;
    if (G[ny][nx] != 'x') continue;
    res = dfs(nx, ny) + 1;
  }
  return res;
}

void dfs_dot(int x, int y, int d) {
  depth[y][x] = d;
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  rep(i, 4) {
    int nx = x + dx[i], ny = y + dy[i];
    if (!is_inside(nx, ny)) continue;
    if (G[ny][nx] != '.') continue;
    if (depth[ny][nx] != -1) continue;
    dfs_dot(nx, ny, d);
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> M;
  rep(y, N + 2) rep(x, M + 2) G[y][x] = '.';
  rep(y, N) rep(x, M) cin >> G[y + 1][x + 1];
  rep(y, N + 2) rep(x, M + 2) depth[y][x] = -1;
  N += 2; M += 2;

  int d = -1;
  rep(y, N) rep(x, M) {
    if (G[y][x] == 'x') {
      num[d] += dfs(x, y);
    }
    if (G[y][x] == '.') {
      if (depth[y][x] == -1) dfs_dot(x, y, d + 1);
      d = depth[y][x];
    }
  }

  //rep(y, N) {
  //  rep(x, M) cout << depth[y][x];
  //  cout << endl;
  //}

  int ans = 0, tmp = 0;
  for (int i = 0; i < 1000; i += 2) tmp += num[i];
  ans = tmp; tmp = 0;
  for (int i = 1; i < 1001; i += 2) tmp += num[i];
  ans = max(ans, tmp);

  cout << ans << endl;

  return 0;
}
0