結果
問題 |
No.1701 half price
|
ユーザー |
![]() |
提出日時 | 2021-10-08 22:02:05 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 902 bytes |
コンパイル時間 | 2,281 ms |
コンパイル使用メモリ | 78,128 KB |
実行使用メモリ | 54,228 KB |
最終ジャッジ日時 | 2024-07-23 04:16:07 |
合計ジャッジ時間 | 6,804 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 4 |
ソースコード
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 = 0; 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); } }