結果
問題 | No.421 しろくろチョコレート |
ユーザー | hermione17 |
提出日時 | 2016-09-09 23:10:30 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 236 ms / 2,000 ms |
コード長 | 1,911 bytes |
コンパイル時間 | 3,401 ms |
コンパイル使用メモリ | 77,228 KB |
実行使用メモリ | 58,784 KB |
最終ジャッジ日時 | 2024-09-23 07:06:27 |
合計ジャッジ時間 | 15,312 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 131 ms
54,012 KB |
testcase_01 | AC | 163 ms
56,256 KB |
testcase_02 | AC | 124 ms
55,080 KB |
testcase_03 | AC | 135 ms
53,860 KB |
testcase_04 | AC | 136 ms
53,964 KB |
testcase_05 | AC | 154 ms
54,128 KB |
testcase_06 | AC | 155 ms
54,336 KB |
testcase_07 | AC | 161 ms
56,392 KB |
testcase_08 | AC | 139 ms
56,336 KB |
testcase_09 | AC | 152 ms
54,436 KB |
testcase_10 | AC | 121 ms
53,120 KB |
testcase_11 | AC | 163 ms
56,168 KB |
testcase_12 | AC | 119 ms
52,700 KB |
testcase_13 | AC | 131 ms
53,860 KB |
testcase_14 | AC | 130 ms
54,116 KB |
testcase_15 | AC | 127 ms
54,008 KB |
testcase_16 | AC | 179 ms
58,284 KB |
testcase_17 | AC | 175 ms
57,660 KB |
testcase_18 | AC | 183 ms
58,300 KB |
testcase_19 | AC | 128 ms
53,876 KB |
testcase_20 | AC | 161 ms
56,296 KB |
testcase_21 | AC | 175 ms
57,668 KB |
testcase_22 | AC | 159 ms
56,576 KB |
testcase_23 | AC | 130 ms
53,896 KB |
testcase_24 | AC | 119 ms
54,028 KB |
testcase_25 | AC | 127 ms
54,196 KB |
testcase_26 | AC | 129 ms
53,776 KB |
testcase_27 | AC | 130 ms
54,112 KB |
testcase_28 | AC | 164 ms
57,544 KB |
testcase_29 | AC | 173 ms
57,600 KB |
testcase_30 | AC | 166 ms
56,980 KB |
testcase_31 | AC | 232 ms
58,608 KB |
testcase_32 | AC | 172 ms
57,616 KB |
testcase_33 | AC | 170 ms
57,760 KB |
testcase_34 | AC | 124 ms
52,788 KB |
testcase_35 | AC | 137 ms
53,840 KB |
testcase_36 | AC | 152 ms
56,008 KB |
testcase_37 | AC | 183 ms
58,112 KB |
testcase_38 | AC | 212 ms
58,404 KB |
testcase_39 | AC | 138 ms
55,996 KB |
testcase_40 | AC | 184 ms
58,344 KB |
testcase_41 | AC | 165 ms
54,464 KB |
testcase_42 | AC | 155 ms
54,024 KB |
testcase_43 | AC | 153 ms
56,044 KB |
testcase_44 | AC | 208 ms
58,448 KB |
testcase_45 | AC | 134 ms
54,004 KB |
testcase_46 | AC | 137 ms
53,884 KB |
testcase_47 | AC | 158 ms
56,652 KB |
testcase_48 | AC | 236 ms
58,784 KB |
testcase_49 | AC | 139 ms
56,292 KB |
testcase_50 | AC | 136 ms
53,892 KB |
testcase_51 | AC | 214 ms
58,548 KB |
testcase_52 | AC | 159 ms
56,604 KB |
testcase_53 | AC | 138 ms
54,188 KB |
testcase_54 | AC | 140 ms
56,244 KB |
testcase_55 | AC | 139 ms
54,088 KB |
testcase_56 | AC | 153 ms
54,368 KB |
testcase_57 | AC | 139 ms
54,060 KB |
testcase_58 | AC | 161 ms
56,408 KB |
testcase_59 | AC | 153 ms
54,424 KB |
testcase_60 | AC | 225 ms
58,564 KB |
testcase_61 | AC | 209 ms
58,524 KB |
testcase_62 | AC | 134 ms
54,132 KB |
testcase_63 | AC | 131 ms
53,968 KB |
testcase_64 | AC | 138 ms
53,972 KB |
ソースコード
import java.util.Scanner; public class Y421 { int N, M; char[][] S; int[][] matchRow, matchCol; boolean[][] checked; Y421() { Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); S = new char[N][]; for (int i = 0; i < S.length; i++) { S[i] = sc.next().toCharArray(); } matchRow = new int[N][M]; matchCol = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { matchRow[i][j] = -1; matchCol[i][j] = -1; } } int cnt = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (matchCol[i][j] == -1 && S[i][j] != '.') { checked = new boolean[N][M]; if (search(i, j)) { cnt++; } } } } int black = 0, white = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (matchCol[i][j] < 0) { if (S[i][j] == 'b') black++; if (S[i][j] == 'w') white++; } } } int happiness = cnt * 100 + 10 * Math.min(black, white) + Math.abs(black - white); System.out.println(happiness); } boolean search(int i, int j) { if (checked[i][j]) { return false; } checked[i][j] = true; int[] i_array = { i, i-1, i, i+1 }; int[] j_array = { j-1, j, j+1, j }; for (int i2 : i_array) { for (int j2 : j_array) { if (0 <= i2 && i2 < N && 0 <= j2 && j2 < M) { if (S[i2][j2] != '.' && S[i][j] != S[i2][j2]) { if (matchCol[i2][j2] < 0 || search(matchRow[i2][j2], matchCol[i2][j2])) { matchCol[i][j] = j2; matchRow[i][j] = i2; matchCol[i2][j2] = j; matchRow[i2][j2] = i; return true; } } } } } return false; } public static void main(String argv[]) { new Y421(); } }