Submission #54608270
Source Code Expand
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); // 売り場の数
int M = sc.nextInt(); // 味の種類の数
sc.nextLine(); // 改行を消費
List<Set<Integer>> popcornInfo = new ArrayList<>();
// 各売り場の情報を読み取る
for (int i = 0; i < N; i++) {
String s = sc.nextLine();
Set<Integer> tastes = new HashSet<>();
for (int j = 0; j < M; j++) {
if (s.charAt(j) == 'o') {
tastes.add(j);
}
}
popcornInfo.add(tastes);
}
int minCount = N; // 最大N個の売り場を訪れる可能性があるので、初期値をNに設定
// 2^N通りの組み合わせを試行
for (int i = 0; i < (1 << N); i++) {
Set<Integer> allTastes = new HashSet<>();
int count = 0;
for (int j = 0; j < N; j++) {
if ((i & (1 << j)) != 0) {
allTastes.addAll(popcornInfo.get(j));
count++;
}
}
// すべての味をカバーしているか確認
if (allTastes.size() == M) {
minCount = Math.min(minCount, count);
}
}
// 結果を出力
System.out.println(minCount);
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Popcorn |
| User | andrywawa |
| Language | Java (OpenJDK 17) |
| Score | 300 |
| Code Size | 1508 Byte |
| Status | AC |
| Exec Time | 101 ms |
| Memory | 39488 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 70 ms | 38216 KiB |
| 00_sample_01.txt | AC | 69 ms | 38208 KiB |
| 00_sample_02.txt | AC | 72 ms | 38068 KiB |
| 01_random_00.txt | AC | 83 ms | 38992 KiB |
| 01_random_01.txt | AC | 93 ms | 39168 KiB |
| 01_random_02.txt | AC | 85 ms | 39112 KiB |
| 01_random_03.txt | AC | 93 ms | 39280 KiB |
| 01_random_04.txt | AC | 96 ms | 39256 KiB |
| 01_random_05.txt | AC | 84 ms | 39288 KiB |
| 01_random_06.txt | AC | 82 ms | 39404 KiB |
| 01_random_07.txt | AC | 82 ms | 39048 KiB |
| 01_random_08.txt | AC | 82 ms | 39116 KiB |
| 01_random_09.txt | AC | 82 ms | 39392 KiB |
| 01_random_10.txt | AC | 98 ms | 39196 KiB |
| 01_random_11.txt | AC | 97 ms | 39132 KiB |
| 01_random_12.txt | AC | 101 ms | 39396 KiB |
| 01_random_13.txt | AC | 96 ms | 39388 KiB |
| 01_random_14.txt | AC | 97 ms | 39208 KiB |
| 01_random_15.txt | AC | 95 ms | 39444 KiB |
| 01_random_16.txt | AC | 97 ms | 39400 KiB |
| 01_random_17.txt | AC | 97 ms | 39440 KiB |
| 01_random_18.txt | AC | 94 ms | 39140 KiB |
| 01_random_19.txt | AC | 97 ms | 39208 KiB |
| 01_random_20.txt | AC | 99 ms | 39488 KiB |
| 02_handmade_00.txt | AC | 98 ms | 38824 KiB |
| 02_handmade_01.txt | AC | 72 ms | 37836 KiB |
| 02_handmade_02.txt | AC | 84 ms | 39040 KiB |
| 02_handmade_03.txt | AC | 73 ms | 38084 KiB |