結果
問題 | No.1701 half price |
ユーザー |
![]() |
提出日時 | 2021-10-08 22:03:59 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 270 ms / 3,000 ms |
コード長 | 902 bytes |
コンパイル時間 | 2,038 ms |
コンパイル使用メモリ | 78,072 KB |
実行使用メモリ | 56,600 KB |
最終ジャッジ日時 | 2024-07-23 04:19:07 |
合計ジャッジ時間 | 6,165 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int w = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); int ans = 0; int end = 1 << n; for (int i = 1; i < end; i++) { List<Integer> list = new ArrayList<>(); for (int j = 0; j < n; j++) { if ((i >> j & 1) == 1) { list.add(a[j]); } } int size = list.size(); int end2 = 1 << size; for (int j = 0; j < end2; j++) { long sum = 0; for (int j2 = 0; j2 < size; j2++) { if ((j >> j2 & 1) == 1) { sum += list.get(j2) / 2; } else { sum += list.get(j2); } } if (sum == w) { ans++; break; } } } System.out.println(ans); } }