Submission #5014304
Source Code Expand
import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { int n = scanner.nextInt(); int m = scanner.nextInt(); scanner.nextLine(); boolean relation[][] = new boolean[n][n]; IntStream.range(0, n).forEach(i -> { IntStream.range(0, n).forEach(j -> relation[i][j] = false); }); IntStream.range(0, n).forEach(i -> relation[i][i] = true); IntStream.range(0, m).forEach(i -> { int x = scanner.nextInt(); int y = scanner.nextInt(); scanner.nextLine(); relation[x - 1][y - 1] = relation[y - 1][x - 1] = true; }); List<Integer> list = IntStream.range(1, (int) Math.pow(2, n)).boxed() .sorted((x, y) -> oneCount(y) - oneCount(x)).collect(Collectors.toList()); for (Integer integer : list) { Set<Integer> set = new HashSet<>(); for (int j = 0; j < n; j++) { if (1 == (1 & (integer >> j))) { set.add(j); } } if (check(set, relation)) { System.out.println(set.size()); break; } } } } /** * @param x * @return xの2進数表現の1の数 */ private static int oneCount(int x) { int count = 0; for (int i = 0; i < 32; i++) { if (1 == (1 & (x >> i))) { count++; } } return count; } private static boolean check(Set<Integer> set, boolean[][] relation) { for (Integer i : set) { for (Integer j : set) { if (!relation[i][j]) { return false; } } } return true; } }
Submission Info
Submission Time | |
---|---|
Task | D - 派閥 |
User | danielsun3164 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 100 |
Code Size | 1703 Byte |
Status | AC |
Exec Time | 255 ms |
Memory | 31060 KB |
Judge Result
Set Name | all | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
all | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 255 ms | 28244 KB |
00_sample_02.txt | AC | 191 ms | 25684 KB |
00_sample_03.txt | AC | 200 ms | 25044 KB |
00_sample_04.txt | AC | 238 ms | 28756 KB |
test_01.txt | AC | 183 ms | 28500 KB |
test_02.txt | AC | 180 ms | 26964 KB |
test_03.txt | AC | 181 ms | 26580 KB |
test_04.txt | AC | 188 ms | 26452 KB |
test_05.txt | AC | 180 ms | 24532 KB |
test_06.txt | AC | 186 ms | 26836 KB |
test_07.txt | AC | 184 ms | 26580 KB |
test_08.txt | AC | 195 ms | 26836 KB |
test_09.txt | AC | 193 ms | 24528 KB |
test_10.txt | AC | 215 ms | 27092 KB |
test_11.txt | AC | 217 ms | 26960 KB |
test_12.txt | AC | 215 ms | 26572 KB |
test_13.txt | AC | 186 ms | 26964 KB |
test_14.txt | AC | 187 ms | 26448 KB |
test_15.txt | AC | 190 ms | 27092 KB |
test_16.txt | AC | 199 ms | 26964 KB |
test_17.txt | AC | 206 ms | 24656 KB |
test_18.txt | AC | 221 ms | 27084 KB |
test_19.txt | AC | 230 ms | 26836 KB |
test_20.txt | AC | 208 ms | 27092 KB |
test_21.txt | AC | 192 ms | 24528 KB |
test_22.txt | AC | 205 ms | 26580 KB |
test_23.txt | AC | 218 ms | 25300 KB |
test_24.txt | AC | 203 ms | 27092 KB |
test_25.txt | AC | 195 ms | 26964 KB |
test_26.txt | AC | 225 ms | 26836 KB |
test_27.txt | AC | 221 ms | 26828 KB |
test_28.txt | AC | 185 ms | 24912 KB |
test_29.txt | AC | 189 ms | 24660 KB |
test_30.txt | AC | 209 ms | 23636 KB |
test_31.txt | AC | 222 ms | 26448 KB |
test_32.txt | AC | 222 ms | 26956 KB |
test_33.txt | AC | 207 ms | 24916 KB |
test_34.txt | AC | 216 ms | 24912 KB |
test_35.txt | AC | 211 ms | 24524 KB |
test_36.txt | AC | 209 ms | 27348 KB |
test_37.txt | AC | 232 ms | 26964 KB |
test_38.txt | AC | 217 ms | 26960 KB |
test_39.txt | AC | 216 ms | 25424 KB |
test_40.txt | AC | 231 ms | 29396 KB |
test_41.txt | AC | 206 ms | 28372 KB |
test_42.txt | AC | 205 ms | 26836 KB |
test_43.txt | AC | 226 ms | 26964 KB |
test_44.txt | AC | 225 ms | 26580 KB |
test_45.txt | AC | 218 ms | 26836 KB |
test_46.txt | AC | 216 ms | 25292 KB |
test_47.txt | AC | 206 ms | 24784 KB |
test_48.txt | AC | 211 ms | 29140 KB |
test_49.txt | AC | 230 ms | 27344 KB |
test_50.txt | AC | 228 ms | 31060 KB |
test_51.txt | AC | 232 ms | 25172 KB |
test_52.txt | AC | 225 ms | 26580 KB |
test_53.txt | AC | 221 ms | 26452 KB |
test_54.txt | AC | 221 ms | 26580 KB |
test_55.txt | AC | 224 ms | 25164 KB |
test_56.txt | AC | 222 ms | 25428 KB |
test_57.txt | AC | 206 ms | 26452 KB |
test_58.txt | AC | 210 ms | 25040 KB |
test_59.txt | AC | 215 ms | 23636 KB |
test_60.txt | AC | 214 ms | 24912 KB |
test_61.txt | AC | 214 ms | 28880 KB |
test_62.txt | AC | 185 ms | 25172 KB |
test_63.txt | AC | 215 ms | 24516 KB |
test_64.txt | AC | 225 ms | 27092 KB |
test_65.txt | AC | 225 ms | 28496 KB |
test_66.txt | AC | 218 ms | 27348 KB |
test_67.txt | AC | 229 ms | 26960 KB |
test_68.txt | AC | 236 ms | 29140 KB |
test_69.txt | AC | 225 ms | 26708 KB |
test_70.txt | AC | 226 ms | 25172 KB |