結果

問題 No.421 しろくろチョコレート
ユーザー akun0716
提出日時 2020-04-30 21:57:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 2,283 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 96,072 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-17 19:07:18
合計ジャッジ時間 5,308 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46 WA * 1 RE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
#include <cstring>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;
VI G[2000];
int match[2010];
bool used[2010];
int N;
bool dfs(int v) {
used[v] = true;
REP(i, G[v].size()) {
int u = G[v][i], w = match[u];
if (w < 0 || (!used[w] && dfs(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int solve() {
int res = 0;
memset(match, -1, sizeof(match));
REP(v, N) {
if (match[v] < 0) {
memset(used, 0, sizeof(used));
if (dfs(v))res++;
}
}
return res;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W; cin >> H >> W;
VS S(H);
REP(i, H)cin >> S[i];
N = H * W;
map<pii, int>mp;
int w = 0, b = 0;
int k = 0;
REP(i, H)REP(j, W)mp[pii(i,j)] = k++;
int dx[] = { 0,0,-1,1 };
int dy[] = { -1,1,0,0 };
REP(i, H) {
REP(j, W) {
if (S[i][j] == 'w')w++;
if (S[i][j] == 'b')b++;
REP(k, 4) {
int nx = i + dx[k], ny = j + dy[k];
if (nx >= 0 && nx < H&&ny >= 0 && ny < W) {
if (S[i][j] != S[nx][ny] && S[i][j] != '.' && S[nx][ny] != '.') {
G[mp[pii(i, j)]].push_back(mp[pii(nx, ny)]);
}
}
}
}
}
int ans = solve() * 100;
w -= ans / 100;
b -= ans / 100;
ans += min(w, b) * 10;
ans += abs(w - b);
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0