結果

問題 No.348 カゴメカゴメ
ユーザー alpha_virginisalpha_virginis
提出日時 2016-02-27 00:06:39
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,480 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 72,180 KB
実行使用メモリ 15,920 KB
最終ジャッジ日時 2023-10-24 17:59:33
合計ジャッジ時間 7,400 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |     scanf("%s", field[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>

int N, M;
char field[1024][1024];

int bfs(int y, int x, char c1, char c2) {
  int res = 0;
  std::queue<int> xs;
  std::queue<int> ys;
  xs.push(x); ys.push(y);
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  while( not xs.empty() ) {
    x = xs.front(); xs.pop();
    y = ys.front(); ys.pop();
    if( field[y][x] == c1 ) {
      field[y][x] = c2;
      res += 1;
    }
    else continue;
    for(int k = 0; k < 4; ++k) {
      int nx = x + dx[k];
      int ny = y + dy[k];
      if( not ( 0 <= nx and nx < M and 0 <= ny and ny < N ) ) continue;
      if( field[ny][nx] == c1 ) {
        xs.push(nx); ys.push(ny);
      }
    }
  }
  return res;
}
  
int main() {
  std::cin >> N >> M;
  for(int i = 0; i < N; ++i) {
    scanf("%s", field[i]);
  }

  int res = 0;
  int t1 = 0;
  for(int y : {0, N - 1}) {
    for(int x = 0; x < M; ++x) {
      t1 += bfs(y, x, '.', 'x');
    }
  }
  for(int y = 0; y < N; ++y) {
    for(int x : {0, M - 1}) {
      t1 += bfs(y, x, '.', 'x');
    }
  }

  int aa = bfs(0, 0, 'x', '.');
  res += aa - t1;

  int count = 0;
  for(;;) {
    count += 1;
    if( count >= 100 ) break;
    bfs(0, 0, '.', 'x');
    bfs(0, 0, 'x', '.');
    int s = bfs(0, 0, '.', 'x');
    if( s == N * M ) break;
    int d = bfs(0, 0, 'x', '.');
    res += d - s;
  }

  printf("%d\n", res);
  
  return 0;
}
0