結果
問題 | No.483 マッチ並べ |
ユーザー | uafr_cs |
提出日時 | 2017-02-10 23:21:37 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 150 ms / 2,000 ms |
コード長 | 2,444 bytes |
コンパイル時間 | 2,429 ms |
コンパイル使用メモリ | 79,956 KB |
実行使用メモリ | 54,520 KB |
最終ジャッジ日時 | 2024-06-09 07:47:14 |
合計ジャッジ時間 | 10,011 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
53,776 KB |
testcase_01 | AC | 105 ms
52,760 KB |
testcase_02 | AC | 112 ms
54,184 KB |
testcase_03 | AC | 118 ms
54,056 KB |
testcase_04 | AC | 111 ms
53,844 KB |
testcase_05 | AC | 104 ms
54,004 KB |
testcase_06 | AC | 116 ms
54,272 KB |
testcase_07 | AC | 115 ms
54,192 KB |
testcase_08 | AC | 108 ms
53,668 KB |
testcase_09 | AC | 117 ms
53,916 KB |
testcase_10 | AC | 116 ms
54,148 KB |
testcase_11 | AC | 116 ms
53,968 KB |
testcase_12 | AC | 113 ms
53,956 KB |
testcase_13 | AC | 101 ms
53,096 KB |
testcase_14 | AC | 114 ms
54,256 KB |
testcase_15 | AC | 121 ms
54,076 KB |
testcase_16 | AC | 123 ms
54,428 KB |
testcase_17 | AC | 119 ms
54,164 KB |
testcase_18 | AC | 119 ms
53,852 KB |
testcase_19 | AC | 121 ms
54,200 KB |
testcase_20 | AC | 109 ms
53,704 KB |
testcase_21 | AC | 122 ms
54,304 KB |
testcase_22 | AC | 116 ms
54,056 KB |
testcase_23 | AC | 118 ms
54,044 KB |
testcase_24 | AC | 103 ms
53,160 KB |
testcase_25 | AC | 111 ms
54,252 KB |
testcase_26 | AC | 120 ms
53,932 KB |
testcase_27 | AC | 141 ms
54,404 KB |
testcase_28 | AC | 149 ms
54,512 KB |
testcase_29 | AC | 142 ms
54,228 KB |
testcase_30 | AC | 133 ms
53,908 KB |
testcase_31 | AC | 135 ms
54,128 KB |
testcase_32 | AC | 147 ms
54,048 KB |
testcase_33 | AC | 118 ms
54,040 KB |
testcase_34 | AC | 129 ms
54,272 KB |
testcase_35 | AC | 129 ms
53,856 KB |
testcase_36 | AC | 121 ms
53,912 KB |
testcase_37 | AC | 122 ms
54,188 KB |
testcase_38 | AC | 143 ms
54,172 KB |
testcase_39 | AC | 141 ms
54,120 KB |
testcase_40 | AC | 145 ms
54,144 KB |
testcase_41 | AC | 140 ms
54,384 KB |
testcase_42 | AC | 139 ms
53,904 KB |
testcase_43 | AC | 150 ms
54,340 KB |
testcase_44 | AC | 121 ms
54,040 KB |
testcase_45 | AC | 123 ms
54,200 KB |
testcase_46 | AC | 115 ms
53,308 KB |
testcase_47 | AC | 127 ms
54,200 KB |
testcase_48 | AC | 144 ms
54,260 KB |
testcase_49 | AC | 123 ms
54,184 KB |
testcase_50 | AC | 144 ms
54,008 KB |
testcase_51 | AC | 129 ms
54,332 KB |
testcase_52 | AC | 142 ms
54,520 KB |
testcase_53 | AC | 101 ms
53,084 KB |
testcase_54 | AC | 116 ms
54,056 KB |
testcase_55 | AC | 118 ms
54,044 KB |
ソースコード
import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static boolean augment(boolean[][] adj, int node, int[] n_to_m, int[] m_to_n, boolean[] visited){ final int n = adj.length; final int m = adj[0].length; if(node < 0){ return true; } for(int match = 0; match < m; match++){ if(!adj[node][match]){ continue; } if(visited[match]){ continue; } visited[match] = true; if(augment(adj, m_to_n[match], n_to_m, m_to_n, visited)){ n_to_m[node] = match; m_to_n[match] = node; return true; } } return false; } public static int matching(boolean[][] adj){ final int n = adj.length; final int m = adj[0].length; int[] n_to_m = new int[n]; int[] m_to_n = new int[m]; Arrays.fill(n_to_m, -1); Arrays.fill(m_to_n, -1); int match = 0; for(int node = 0; node < n; node++){ boolean[] visited = new boolean[m]; if(augment(adj, node, n_to_m, m_to_n, visited)){ match++; } } return match; } public static final int toInt(int x, int y){ return y * 120 + x; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int n = sc.nextInt(); int[] f_rs = new int[n]; int[] f_cs = new int[n]; int[] s_rs = new int[n]; int[] s_cs = new int[n]; for(int i = 0; i < n; i++){ final int f_r = sc.nextInt(); final int f_c = sc.nextInt(); final int s_r = sc.nextInt(); final int s_c = sc.nextInt(); f_rs[i] = f_r; f_cs[i] = f_c; s_rs[i] = s_r; s_cs[i] = s_c; } int points = 0; HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int i = 0; i < n; i++){ final int f_hash = toInt(f_rs[i], f_cs[i]); if(!map.containsKey(f_hash)){ map.put(f_hash, points++); } final int s_hash = toInt(s_rs[i], s_cs[i]); if(!map.containsKey(s_hash)){ map.put(s_hash, points++); } } boolean[][] adj = new boolean[n][points]; for(int i = 0; i < n; i++){ final int f_hash = toInt(f_rs[i], f_cs[i]); final int s_hash = toInt(s_rs[i], s_cs[i]); final int f_index = map.get(f_hash); final int s_index = map.get(s_hash); adj[i][f_index] = adj[i][s_index] = true; } System.out.println(matching(adj) == n ? "YES" : "NO"); } }