結果
問題 |
No.421 しろくろチョコレート
|
ユーザー |
![]() |
提出日時 | 2020-04-30 21:57:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 2,283 bytes |
コンパイル時間 | 1,111 ms |
コンパイル使用メモリ | 96,100 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-23 07:25:30 |
合計ジャッジ時間 | 2,749 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 65 |
ソースコード
#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[5000]; int match[5010]; bool used[5010]; 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; }