結果
問題 | No.421 しろくろチョコレート |
ユーザー | Hachimori |
提出日時 | 2016-09-09 23:37:41 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,394 bytes |
コンパイル時間 | 477 ms |
コンパイル使用メモリ | 55,900 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-11-16 18:41:35 |
合計ジャッジ時間 | 4,023 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 10 ms
12,416 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 7 ms
12,288 KB |
testcase_13 | AC | 8 ms
12,288 KB |
testcase_14 | AC | 7 ms
12,288 KB |
testcase_15 | AC | 7 ms
12,160 KB |
testcase_16 | WA | - |
testcase_17 | AC | 58 ms
12,416 KB |
testcase_18 | AC | 87 ms
12,288 KB |
testcase_19 | AC | 7 ms
12,288 KB |
testcase_20 | AC | 20 ms
12,416 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 7 ms
12,288 KB |
testcase_24 | AC | 7 ms
12,160 KB |
testcase_25 | AC | 7 ms
12,288 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 21 ms
12,288 KB |
testcase_29 | AC | 29 ms
12,288 KB |
testcase_30 | AC | 22 ms
12,160 KB |
testcase_31 | AC | 263 ms
12,416 KB |
testcase_32 | AC | 20 ms
12,160 KB |
testcase_33 | AC | 28 ms
12,288 KB |
testcase_34 | AC | 11 ms
12,160 KB |
testcase_35 | AC | 12 ms
12,288 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 225 ms
12,288 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | AC | 10 ms
12,288 KB |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | AC | 14 ms
12,288 KB |
testcase_59 | WA | - |
testcase_60 | AC | 258 ms
12,288 KB |
testcase_61 | AC | 45 ms
12,288 KB |
testcase_62 | WA | - |
testcase_63 | AC | 8 ms
12,416 KB |
testcase_64 | AC | 12 ms
12,288 KB |
ソースコード
#include<iostream> #include<cstring> using namespace std; const int SIZE = 55; const int NODE = SIZE * SIZE; int row, col; char ch[SIZE][SIZE]; void read() { cin >> row >> col; for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { cin >> ch[i][j]; } } } bool dfs(int curr, int L2R[NODE], int R2L[NODE], bool visited[NODE], int nNode, bool adj[NODE][NODE]) { if (curr == -1) return true; visited[curr] = true; for (int i = 0; i < nNode; ++i) { if (!adj[curr][i]) continue; int next = R2L[i]; if (next != -1 && visited[next]) continue; if (dfs(next, L2R, R2L, visited, nNode, adj)) { L2R[curr] = i; R2L[i] = curr; return true; } } return false; } int maxMatch(int nNode, bool adj[NODE][NODE]) { int cnt = 0; int L2R[NODE]; int R2L[NODE]; memset(L2R, -1, sizeof(L2R)); memset(R2L, -1, sizeof(R2L)); for (int i = 0; i < nNode; ++i) { bool visited[NODE] = {}; cnt += dfs(i, L2R, R2L, visited, nNode, adj); } return cnt; } void work() { int cntBlack = 0; int cntWhite = 0; static bool adj[NODE][NODE]; memset(adj, 0, sizeof(adj)); for (int r = 0; r < row; ++r) { for (int c = 0; c < col; ++c) { if (ch[r][c] == '.') continue; cntBlack += ch[r][c] == 'b'; cntWhite += ch[r][c] == 'w'; int selfId = r * row + c; static int dr[] = {-1, 0, 1, 0}; static int dc[] = {0, 1, 0, -1}; for (int i = 0; i < 4; ++i) { int nr = r + dr[i]; int nc = c + dc[i]; if (!(0 <= nr && nr < row && 0 <= nc && nc < col)) continue; if (ch[nr][nc] == '.') continue; int oppId = nr * row + nc; if ((r + c) % 2 == 0) { adj[selfId][oppId] = true; } else { adj[oppId][selfId] = true; } } } } int cntMatch = maxMatch(row * col, adj); cntBlack -= cntMatch; cntWhite -= cntMatch; cout << cntMatch * 100 + min(cntBlack, cntWhite) * 10 + max(cntBlack, cntWhite) - min(cntBlack, cntWhite) << endl; } int main() { read(); work(); return 0; }