結果

問題 No.421 しろくろチョコレート
ユーザー mayoko_mayoko_
提出日時 2016-09-09 23:58:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,956 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 105,052 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 06:02:59
合計ジャッジ時間 2,681 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

string field[55];
bool done[55][55];

int calc(int w, int b) {
    if (w > b) swap(w, b);
    return w*10 + b-w;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> field[i];
    }
    int ans = 0;
    int W = 0, B = 0;
    for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) {
        if (!done[i][j] && field[i][j] != '.') {
            int w = 0, b = 0;
            queue<pii> que;
            que.push(pii(i, j));
            done[i][j] = true;
            while (!que.empty()) {
                pii now = que.front(); que.pop();
                int y = now.first, x = now.second;
                if (field[y][x] == 'w') w++;
                else b++;
                for (int k = 0; k < 4; k++) {
                    int ny = y+dy[k], nx = x+dx[k];
                    if (ny < 0 || ny >= N || nx < 0 || nx >= M) continue;
                    if (done[ny][nx]) continue;
                    if (field[ny][nx] != '.') {
                        done[ny][nx] = true;
                        que.push(pii(ny, nx));
                    }
                }
            }
            ans += min(b, w)*100;
            if (b > w) B += b-w;
            else if (b < w) W += w-b;
        }
    }
    ans += calc(W, B);
    cout << ans << endl;
    return 0;
}
0