結果

問題 No.1701 half price
ユーザー ks2mks2m
提出日時 2021-10-08 22:03:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 261 ms / 3,000 ms
コード長 902 bytes
コンパイル時間 3,243 ms
コンパイル使用メモリ 74,852 KB
実行使用メモリ 57,704 KB
最終ジャッジ日時 2023-09-30 10:13:42
合計ジャッジ時間 6,689 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,932 KB
testcase_01 AC 121 ms
55,936 KB
testcase_02 AC 154 ms
56,052 KB
testcase_03 AC 119 ms
55,908 KB
testcase_04 AC 171 ms
56,920 KB
testcase_05 AC 125 ms
56,112 KB
testcase_06 AC 260 ms
57,704 KB
testcase_07 AC 261 ms
56,032 KB
testcase_08 AC 122 ms
55,508 KB
testcase_09 AC 125 ms
55,660 KB
testcase_10 AC 118 ms
55,872 KB
testcase_11 AC 122 ms
56,204 KB
testcase_12 AC 120 ms
55,824 KB
testcase_13 AC 121 ms
56,016 KB
testcase_14 AC 121 ms
56,256 KB
testcase_15 AC 118 ms
55,764 KB
testcase_16 AC 118 ms
56,004 KB
testcase_17 AC 132 ms
55,548 KB
testcase_18 AC 121 ms
55,740 KB
testcase_19 AC 122 ms
55,472 KB
testcase_20 AC 120 ms
56,244 KB
testcase_21 AC 245 ms
55,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0