結果
問題 | No.421 しろくろチョコレート |
ユーザー | 37zigen |
提出日時 | 2016-09-09 01:24:13 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,391 bytes |
コンパイル時間 | 4,121 ms |
コンパイル使用メモリ | 85,208 KB |
実行使用メモリ | 53,480 KB |
最終ジャッジ日時 | 2024-11-16 08:45:15 |
合計ジャッジ時間 | 26,766 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
40,360 KB |
testcase_01 | AC | 457 ms
53,480 KB |
testcase_02 | AC | 883 ms
49,528 KB |
testcase_03 | AC | 164 ms
43,176 KB |
testcase_04 | AC | 494 ms
49,656 KB |
testcase_05 | AC | 201 ms
45,584 KB |
testcase_06 | AC | 123 ms
40,120 KB |
testcase_07 | AC | 187 ms
45,488 KB |
testcase_08 | WA | - |
testcase_09 | AC | 149 ms
41,924 KB |
testcase_10 | AC | 192 ms
45,728 KB |
testcase_11 | AC | 204 ms
45,840 KB |
testcase_12 | AC | 119 ms
39,988 KB |
testcase_13 | AC | 118 ms
40,024 KB |
testcase_14 | AC | 132 ms
41,516 KB |
testcase_15 | AC | 130 ms
41,680 KB |
testcase_16 | AC | 261 ms
46,908 KB |
testcase_17 | AC | 266 ms
46,844 KB |
testcase_18 | AC | 242 ms
47,188 KB |
testcase_19 | AC | 114 ms
40,224 KB |
testcase_20 | AC | 250 ms
46,736 KB |
testcase_21 | AC | 231 ms
46,792 KB |
testcase_22 | AC | 222 ms
46,472 KB |
testcase_23 | AC | 116 ms
40,224 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 236 ms
45,432 KB |
testcase_29 | AC | 255 ms
46,648 KB |
testcase_30 | AC | 235 ms
46,588 KB |
testcase_31 | AC | 240 ms
47,184 KB |
testcase_32 | AC | 204 ms
46,916 KB |
testcase_33 | AC | 263 ms
46,732 KB |
testcase_34 | AC | 1,176 ms
47,392 KB |
testcase_35 | AC | 1,216 ms
47,168 KB |
testcase_36 | AC | 274 ms
45,604 KB |
testcase_37 | AC | 227 ms
46,880 KB |
testcase_38 | AC | 251 ms
47,040 KB |
testcase_39 | AC | 671 ms
47,916 KB |
testcase_40 | AC | 211 ms
45,932 KB |
testcase_41 | AC | 171 ms
42,548 KB |
testcase_42 | AC | 172 ms
43,200 KB |
testcase_43 | AC | 570 ms
50,504 KB |
testcase_44 | AC | 238 ms
46,492 KB |
testcase_45 | AC | 397 ms
49,712 KB |
testcase_46 | AC | 256 ms
45,632 KB |
testcase_47 | WA | - |
testcase_48 | AC | 229 ms
46,016 KB |
testcase_49 | AC | 908 ms
49,632 KB |
testcase_50 | WA | - |
testcase_51 | AC | 235 ms
46,636 KB |
testcase_52 | AC | 223 ms
46,396 KB |
testcase_53 | AC | 411 ms
49,632 KB |
testcase_54 | AC | 1,128 ms
47,484 KB |
testcase_55 | AC | 192 ms
45,876 KB |
testcase_56 | AC | 181 ms
45,120 KB |
testcase_57 | AC | 212 ms
45,448 KB |
testcase_58 | AC | 321 ms
46,812 KB |
testcase_59 | AC | 180 ms
45,660 KB |
testcase_60 | AC | 261 ms
46,932 KB |
testcase_61 | AC | 214 ms
46,464 KB |
testcase_62 | AC | 122 ms
40,356 KB |
testcase_63 | AC | 137 ms
41,292 KB |
testcase_64 | AC | 137 ms
41,356 KB |
ソースコード
package No400番台; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Q421 { public static void main(String[] args) { new Q421().solver(); } int[] dx = { 1, -1, 0, 0 }; int[] dy = { 0, 0, 1, -1 }; int h, w; char[][] choco; int[][] comp; void solver() { Scanner sc = new Scanner(System.in); h = sc.nextInt(); w = sc.nextInt(); choco = new char[h][w]; for (int i = 0; i < h; i++) { choco[i] = sc.next().toCharArray(); } comp = new int[h][w]; for (int i = 0; i < h; i++) { Arrays.fill(comp[i], -1); } int color = 0; int ans = 0; int odd = 0, even = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (on_filed(x, y) && comp[y][x] == -1) { ArrayList<Integer>[] g = new ArrayList[h * w]; for (int i = 0; i < h * w; i++) { g[i] = new ArrayList<>(); } ArrayDeque<Pair> que = new ArrayDeque<>(); que.add(new Pair(x, y)); while (!que.isEmpty()) { Pair p = que.poll(); if (comp[p.y][p.x] != -1) continue; comp[p.y][p.x] = color; if ((p.x + p.y) % 2 == 0) even++; else odd++; for (int i = 0; i < 4; i++) { int nx = p.x + dx[i]; int ny = p.y + dy[i]; if (on_filed(nx, ny) && comp[ny][nx] == -1) { int a = id(p.x, p.y); int b = id(nx, ny); g[a].add(b); g[b].add(a); que.add(new Pair(nx, ny)); } } } int the_number_of_matchings = bipartiteMatching(g, (h * w) / 2); ans += the_number_of_matchings * 100; even -= the_number_of_matchings; odd -= the_number_of_matchings; color++; } } } // show_comp(); int common = Math.min(even, odd); ans += common * 10; even -= common; odd -= common; ans += even + odd; System.out.println(ans); } int id(int x, int y) { if ((y + x) % 2 == 0) return (y * w + x) / 2; else return (y * w + x) / 2 + (h * w - 1) / 2 + 1; } boolean on_filed(int x, int y) { if (0 <= x && x < w && 0 <= y && y < h && choco[y][x] != '.') { return true; } else return false; } class Pair { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } } boolean augment(ArrayList<Integer>[] g, int u, Integer[] matchTo, Boolean[] visited) { if (u < 0) return true; for (int v : g[u]) { if (!visited[v]) { visited[v] = true; if (augment(g, matchTo[v], matchTo, visited)) { matchTo[u] = v; matchTo[v] = u; return true; } } } return false; } int bipartiteMatching(ArrayList<Integer>[] g, int L) { final int n = g.length; Integer[] matchTo = new Integer[n]; Arrays.fill(matchTo, -1); matching = new ArrayList<>(); int match = 0; for (int i = 0; i < L; i++) { Boolean[] visited = new Boolean[n]; Arrays.fill(visited, false); if (augment(g, i, matchTo, visited)) match++; } for (int i = 0; i < L; i++) { if (matchTo[i] > 0) matching.add(new Edge(i, matchTo[i])); } return match; } ArrayList<Edge> matching; class Edge { int a; int b; Edge(int a, int b) { this.a = a; this.b = b; } } void show_comp() { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { System.out.print((comp[i][j] == -1 ? "#" : comp[i][j]) + " "); } System.out.println(); } } }