結果
問題 | No.421 しろくろチョコレート |
ユーザー | Hachimori |
提出日時 | 2016-09-09 23:43:01 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 397 ms / 2,000 ms |
コード長 | 2,358 bytes |
コンパイル時間 | 497 ms |
コンパイル使用メモリ | 57,888 KB |
実行使用メモリ | 12,560 KB |
最終ジャッジ日時 | 2024-09-23 07:06:33 |
合計ジャッジ時間 | 4,948 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
12,472 KB |
testcase_01 | AC | 16 ms
12,328 KB |
testcase_02 | AC | 9 ms
12,432 KB |
testcase_03 | AC | 5 ms
12,436 KB |
testcase_04 | AC | 7 ms
12,340 KB |
testcase_05 | AC | 6 ms
12,400 KB |
testcase_06 | AC | 5 ms
12,356 KB |
testcase_07 | AC | 15 ms
12,340 KB |
testcase_08 | AC | 10 ms
12,320 KB |
testcase_09 | AC | 6 ms
12,248 KB |
testcase_10 | AC | 5 ms
12,248 KB |
testcase_11 | AC | 15 ms
12,168 KB |
testcase_12 | AC | 5 ms
12,264 KB |
testcase_13 | AC | 4 ms
12,328 KB |
testcase_14 | AC | 4 ms
12,424 KB |
testcase_15 | AC | 5 ms
12,404 KB |
testcase_16 | AC | 33 ms
12,408 KB |
testcase_17 | AC | 85 ms
12,308 KB |
testcase_18 | AC | 134 ms
12,296 KB |
testcase_19 | AC | 5 ms
12,136 KB |
testcase_20 | AC | 25 ms
12,116 KB |
testcase_21 | AC | 33 ms
12,256 KB |
testcase_22 | AC | 17 ms
12,448 KB |
testcase_23 | AC | 4 ms
12,240 KB |
testcase_24 | AC | 4 ms
12,376 KB |
testcase_25 | AC | 5 ms
12,248 KB |
testcase_26 | AC | 4 ms
12,292 KB |
testcase_27 | AC | 5 ms
12,364 KB |
testcase_28 | AC | 27 ms
12,336 KB |
testcase_29 | AC | 38 ms
12,560 KB |
testcase_30 | AC | 29 ms
12,396 KB |
testcase_31 | AC | 397 ms
12,388 KB |
testcase_32 | AC | 25 ms
12,316 KB |
testcase_33 | AC | 38 ms
12,308 KB |
testcase_34 | AC | 13 ms
12,120 KB |
testcase_35 | AC | 12 ms
12,240 KB |
testcase_36 | AC | 10 ms
12,404 KB |
testcase_37 | AC | 225 ms
12,352 KB |
testcase_38 | AC | 353 ms
12,420 KB |
testcase_39 | AC | 9 ms
12,484 KB |
testcase_40 | AC | 69 ms
12,288 KB |
testcase_41 | AC | 13 ms
12,440 KB |
testcase_42 | AC | 7 ms
12,288 KB |
testcase_43 | AC | 9 ms
12,260 KB |
testcase_44 | AC | 160 ms
12,356 KB |
testcase_45 | AC | 8 ms
12,384 KB |
testcase_46 | AC | 5 ms
12,364 KB |
testcase_47 | AC | 14 ms
12,392 KB |
testcase_48 | AC | 212 ms
12,396 KB |
testcase_49 | AC | 10 ms
12,288 KB |
testcase_50 | AC | 7 ms
12,296 KB |
testcase_51 | AC | 234 ms
12,336 KB |
testcase_52 | AC | 11 ms
12,200 KB |
testcase_53 | AC | 7 ms
12,280 KB |
testcase_54 | AC | 11 ms
12,360 KB |
testcase_55 | AC | 5 ms
12,436 KB |
testcase_56 | AC | 5 ms
12,392 KB |
testcase_57 | AC | 6 ms
12,304 KB |
testcase_58 | AC | 14 ms
12,356 KB |
testcase_59 | AC | 8 ms
12,264 KB |
testcase_60 | AC | 397 ms
12,340 KB |
testcase_61 | AC | 67 ms
12,444 KB |
testcase_62 | AC | 5 ms
12,368 KB |
testcase_63 | AC | 4 ms
12,280 KB |
testcase_64 | AC | 12 ms
12,432 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; for (int i = 0; i < nNode; ++i) { if (!adj[curr][i] || visited[i]) continue; visited[i] = true; int next = R2L[i]; 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 * col + 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 * col + 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; }