結果
問題 | No.421 しろくろチョコレート |
ユーザー | uafr_cs |
提出日時 | 2016-09-09 23:29:21 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,778 bytes |
コンパイル時間 | 2,102 ms |
コンパイル使用メモリ | 79,612 KB |
実行使用メモリ | 38,032 KB |
最終ジャッジ日時 | 2024-11-16 18:40:37 |
合計ジャッジ時間 | 6,582 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
37,056 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
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 | 45 ms
36,968 KB |
testcase_13 | AC | 45 ms
37,264 KB |
testcase_14 | AC | 45 ms
36,772 KB |
testcase_15 | AC | 45 ms
36,848 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 44 ms
37,008 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 45 ms
36,992 KB |
testcase_24 | AC | 45 ms
37,208 KB |
testcase_25 | AC | 43 ms
36,632 KB |
testcase_26 | AC | 44 ms
36,752 KB |
testcase_27 | AC | 48 ms
36,744 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 50 ms
37,320 KB |
testcase_35 | AC | 47 ms
37,256 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
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 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | AC | 50 ms
36,648 KB |
testcase_63 | AC | 46 ms
36,756 KB |
testcase_64 | AC | 47 ms
37,236 KB |
ソースコード
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; public class Main { public static boolean augment(ArrayList<HashSet<Integer>> adj, int curr, int[] match, boolean[] visited) { if(curr < 0){ return true; } for(final int next : adj.get(curr)){ if(visited[next]){ continue; } visited[next] = true; if(augment(adj, match[next], match, visited)){ match[curr] = next; match[next] = curr; return true; } } return false; } // black -> white public static int bimatch(ArrayList<HashSet<Integer>> adj, boolean[] is_black, int[] match){ boolean[] visited = new boolean[adj.size()]; Arrays.fill(match, -1); int count = 0; for(int curr = 0; curr < adj.size(); curr++){ if(!is_black[curr]){ continue; } //System.out.println(curr); if(augment(adj, curr, match, visited)){ count++; } } return count; } public static final int[][] move_dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); char[][] map = new char[N][]; for(int i = 0; i < N; i++){ map[i] = sc.next().toCharArray(); } final int size = N * M; ArrayList<HashSet<Integer>> adj = new ArrayList<HashSet<Integer>>(); for(int i = 0; i < size; i++){ adj.add(new HashSet<Integer>()); } boolean[] is_black = new boolean[size]; int white_count = 0, black_count = 0; for(int src_y = 0; src_y < N; src_y++){ for(int src_x = 0; src_x < M; src_x++){ final int curr_id = src_y * M + src_x; is_black[curr_id] = map[src_y][src_x] == 'b'; if(map[src_y][src_x] == 'b'){ black_count++; }else if(map[src_y][src_x] == 'w'){ white_count++; } if(!is_black[curr_id]){ continue; } for(final int[] move : move_dirs){ final int nxt_x = src_x + move[0]; final int nxt_y = src_y + move[1]; if(nxt_x < 0 || nxt_x >= M || nxt_y < 0 || nxt_y >= N){ continue; }else if(map[nxt_y][nxt_x] != 'w'){ continue; } final int next_id = nxt_y * M + nxt_x; adj.get(curr_id).add(next_id); } } } //System.out.println(adj); final int match = bimatch(adj, is_black, new int[size]); final int other = Math.max(0, Math.min(white_count, black_count) - match); final int single = Math.max(white_count, black_count) - match - other; //System.out.println(white_count + " " + black_count); //System.out.println(match + " " + other + " " + single); System.out.println(match * 100 + other * 10 + single); } public static class Scanner implements Closeable { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public void close() throws IOException { br.close(); } } }