結果

問題 No.421 しろくろチョコレート
ユーザー K UK U
提出日時 2023-12-22 13:45:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,098 bytes
コンパイル時間 4,516 ms
コンパイル使用メモリ 273,396 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-22 13:45:22
合計ジャッジ時間 6,120 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#ifdef LOCAL
#include <debug.h>
#define dbg(...) debug::dbg(#__VA_ARGS__, __VA_ARGS__)
#define prt(...) debug::prt(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) void(0)
#define prt(...) void(0)
#endif
using namespace std;

// #define int ll

#define rep(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i < i##_end__; i++)
#define rep_r(i, a, b) for(int i=static_cast<int>(a), i##_end__=static_cast<int>(b); i >= i##_end__; i--)
#define fore(i, a) for(auto& i: a)
#define forei(i, it, a) for(auto [i, it] = std::pair{0, std::begin(a)}; it != std::end(a); i++, it++)
#define all(x) std::begin(x), std::end(x)

using ll = long long; // __int128;
using ull = unsigned long long;
template<class T> using priority_queue_g = priority_queue<T, vector<T>, greater<T>>;

template<class C> int siz(const C& c) { return static_cast<int>(c.size()); }
template<class T, size_t N> constexpr int siz(const T (&)[N]) { return static_cast<int>(N); }
template<class A, class V> inline void fil(A& a, const V &v){ if constexpr(is_array_v<A>) for(auto& s: a) fil(s, v); else a = v; };
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> constexpr T pow2(T x){ return x * x; }
template<class T, class S> constexpr T divceil(T x, S div) { return (x % div == 0) ? x / div : (x >= 0) ? (x / div) + 1 : -((-x) / div); }
template<class T, class S> constexpr T divfloor(T x, S div){ return (x % div == 0) ? x / div : (x >= 0) ? (x / div) : -((-x) / div) - 1; }
template<class T> inline void oneline(T x){ bool f = true; for(auto i: x){ if(f) f = false; else cout << " "; cout << i; } cout << endl; }
inline void yesno(bool x){ cout << (x ? "Yes" : "No") << endl; }
constexpr long long INF = 1LL << 60; // 1.15e18
constexpr int MOD = (int)1e9 + 7;

void _main() {
    int H, W;
    cin >> H >> W;
    vector<string> G(H);
    fore(e, G) cin >> e;
    int S = H * W;
    int T = S + 1;
    int cnt = 0;
    mf_graph<int> mf(T + 1);
    auto f = [&](int y, int x){ return y * W + x; };
    int w = 0, b = 0;
    rep(y, 0, H) rep(x, 0, W){
        if(G[y][x] == '.') continue;
        if(G[y][x] == 'b') b++; else w++;
        cnt++;
        auto id = f(y, x);
        if((y + x) % 2){
            mf.add_edge(id, T, 1);
        }
        else{
            mf.add_edge(S, id, 1);
            for(auto _d : vector<vector<int>>{{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}}){ 
                auto cy = y + _d[0], cx = x + _d[1]; 
                if(cy < 0 || H <= cy || cx < 0 || W <= cx) continue;
                if(G[cy][cx] != '.') mf.add_edge(id, f(cy, cx), 1);
            }
        }

    }
    auto maxflow = mf.flow(S, T);

    int ans = maxflow * 100 + (min(w, b) - maxflow) * 10 + abs(w - b);
    cout << ans << endl;
}

signed main() { 
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15); cerr << fixed << setprecision(15);
    _main();
}
0