結果
問題 | No.421 しろくろチョコレート |
ユーザー |
|
提出日時 | 2023-12-22 13:45:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 3,098 bytes |
コンパイル時間 | 4,871 ms |
コンパイル使用メモリ | 260,488 KB |
最終ジャッジ日時 | 2025-02-18 13:12:37 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 65 |
ソースコード
#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)#endifusing 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.15e18constexpr 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();}