結果

問題 No.421 しろくろチョコレート
ユーザー 🍡yurahuna
提出日時 2016-09-14 01:15:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,930 bytes
コンパイル時間 1,980 ms
コンパイル使用メモリ 180,732 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 05:14:55
合計ジャッジ時間 3,764 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 61
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0