結果

問題 No.421 しろくろチョコレート
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-09-14 01:15:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,930 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 177,252 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-10 20:03:31
合計ジャッジ時間 5,356 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
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 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template<typename T> using Graph = vector<vector<T>>;

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

int H, W;

inline bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

int node(int i, int j) {
    return i * W + j;
}

class BiMatch {
private:
    const int n;
    vector<vector<int>> G;
    vector<int> match;
    vector<bool> used;
    bool dfs(int v) {
        used[v] = true;
        for (const auto& u : G[v]) {
            int w = match[u];
            if (w < 0 || !used[w] && dfs(w)) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
public:
    BiMatch(int _n) : n(_n), G(_n) {}
    void addEdge(int u, int v) {
        G[u].emplace_back(v);
        G[v].emplace_back(v);
    }
    int calc() {
        int res = 0;
        match.clear();
        match.resize(n, -1);
        rep(v, n) {
            if (match[v] < 0) {
                used.clear();
                used.resize(n, false);
                if (dfs(v)) {
                    res++;
                }
            }
        }
        return res;
    }
};

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    cin >> H >> W;
    vector<string> choco(H);
    rep(i, H) cin >> choco[i];

    BiMatch bimatch(H * W);
    int nw = 0, nb = 0;

    rep(i, H) {
        rep(j, W) {
            if (choco[i][j] == 'w') {
                nw++;
                rep(k, 4) {
                    int ni = i + dx[k], nj = j + dy[j];
                    if (inside(ni, nj) && choco[ni][nj] == 'b') {
                        bimatch.addEdge(node(i, j), node(ni, nj));
                    }
                }
            } else if (choco[i][j] == 'b') {
                nb++;
            }
        }
    }

    int num_match = bimatch.calc();
    int ans = 100 * num_match;
    cerr << ans << endl;
    nw -= num_match;
    nb -= num_match;
    ans += 10 * min(nb, nw);
    cerr << ans << endl;
    ans += max(nw - nb, nb - nw);
    cerr << ans << endl;
    cout << ans << endl;
}
0