結果
問題 | No.421 しろくろチョコレート |
ユーザー | vjudge1 |
提出日時 | 2024-12-22 15:30:26 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,703 bytes |
コンパイル時間 | 1,813 ms |
コンパイル使用メモリ | 172,304 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-22 15:30:33 |
合計ジャッジ時間 | 6,105 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | RE | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | RE | - |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | RE | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | WA | - |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | RE | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | RE | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | RE | - |
testcase_44 | WA | - |
testcase_45 | RE | - |
testcase_46 | WA | - |
testcase_47 | RE | - |
testcase_48 | WA | - |
testcase_49 | RE | - |
testcase_50 | WA | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | RE | - |
testcase_57 | RE | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | AC | 2 ms
5,248 KB |
testcase_63 | AC | 2 ms
5,248 KB |
testcase_64 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> #define sz(x) (signed)(x).size() using namespace std; void file_IO(){ freopen("chocolate.in", "r", stdin); freopen("chocolate.out", "w", stdout); } const int N = 55; const int M = 1e5 + 10; const int inf = 20100705; int n, m, S, T, cntw, cntb, ans = 0; char mp[N][N]; int tot = 1, head[N * N], cur[N * N]; struct Edge{ int to, w, nxt; }edge[M]; void add(int u, int v, int w){ edge[++tot].to = v; edge[tot].w = w; edge[tot].nxt = head[u]; head[u] = tot; } int ID(int x, int y){ return (x - 1) * m + y; } bool in(int x, int y){ return 1 <= x && x <= n && 1 <= y && y <= m; } int dis[N]; bool bfs(){ memset(dis, 0x3f, sizeof(dis)); dis[S] = 0, cur[S] = head[S]; queue<int> Q = queue<int>(); Q.push(S); while (sz(Q)){ int u = Q.front(); Q.pop(); for (int i = head[u]; i; i = edge[i].nxt){ int v = edge[i].to; if (edge[i].w > 0 && dis[u] + 1 < dis[v]){ dis[v] = dis[u] + 1; cur[v] = head[v], Q.push(v); if (v == T) return 1; } } } return 0; } int dinic(int u, int sum){ if (u == T) return sum; int res = 0; for (int i = cur[u]; i; i = edge[i].nxt){ int v = edge[i].to; cur[u] = i; if (edge[i].w > 0 && dis[v] == dis[u] + 1){ int t = dinic(v, min(sum, edge[i].w)); if (!t) dis[v] = inf; res += t, sum -= t; edge[i].w -= t, edge[i ^ 1].w += t; if (!sum) break; } } return res; } signed main(){ //file_IO(); cin >> n >> m; S = n * m + 1, T = n * m + 2; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++){ cin >> mp[i][j]; cntw += (mp[i][j] == 'w' ? 1 : 0); cntb += (mp[i][j] == 'b' ? 1 : 0); if (mp[i][j] == 'w') add(S, ID(i, j), 1), add(ID(i, j), S, 0); else if (mp[i][j] == 'b') add(ID(i, j), T, 1), add(T, ID(i, j), 0); } int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; for (int x = 1; x <= n; x++) for (int y = 1; y <= m; y++) if (mp[x][y] != '.'){ for (int i : {0, 1, 2, 3}){ int nx = x + dx[i], ny = y + dy[i]; if (!in(nx, ny) || mp[nx][ny] == '.') continue; (mp[x][y] == 'w' ? add(ID(x, y), ID(nx, ny), 1) : add(ID(x, y), ID(nx, ny), 0)); } } while (bfs()) ans += dinic(S, inf); cout << ans * 100 + (min(cntb, cntw) - ans) * 10 + max(cntb, cntw) - min(cntb, cntw) << endl; return 0; }