結果

問題 No.421 しろくろチョコレート
ユーザー koyumeishikoyumeishi
提出日時 2016-09-07 21:26:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,265 bytes
コンパイル時間 847 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-10 07:16:05
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 WA -
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 2 ms
4,380 KB
testcase_45 WA -
testcase_46 AC 2 ms
4,380 KB
testcase_47 WA -
testcase_48 AC 2 ms
4,376 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 2 ms
4,376 KB
testcase_52 WA -
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 1 ms
4,376 KB
testcase_64 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//連結成分中の白黒の数を数えるだけ。 WAになってないとダメ

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<string> s(n);
  for(auto& x : s) cin >> x;

  vector<vector<bool>> visit(n, vector<bool>(m, false));
  int ans = 0;
  int b = 0, w = 0;

  for(int r=0; r<n; r++)
  for(int c=0; c<m; c++){
    if(visit[r][c] || s[r][c]=='.') continue;
    queue<int> q;
    q.push(r*m + c);
    visit[r][c] = true;
    int cnt_b = 0;
    int cnt_w = 0;

    while(q.size()){
      int p = q.front(); q.pop();
      int y = p/m;
      int x = p%m;
      cnt_b += s[y][x] == 'b';
      cnt_w += s[y][x] == 'w';

      for(int k__=0; k__<4; k__++){
        int new_x = x + dx[k__];
        int new_y = y + dy[k__];
        if(new_x < 0 || new_x >= m || new_y < 0 || new_y >= n) continue;
        if(visit[new_y][new_x] || s[new_y][new_x] == '.') continue;
        visit[new_y][new_x] = true;
        q.push(new_y * m + new_x);
      }
    }

    int d = min(cnt_b, cnt_w);
    ans += d*100;
    b += cnt_b - d;
    w += cnt_w - d;
  }

  ans += min(b,w) * 10;
  ans += max(b,w) - min(b,w);

  cout << ans << endl;
  return 0;
}
0