結果

問題 No.1701 half price
ユーザー ks2mks2m
提出日時 2021-10-08 22:02:05
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 75,980 KB
実行使用メモリ 57,820 KB
最終ジャッジ日時 2023-09-30 10:10:39
合計ジャッジ時間 7,378 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,068 KB
testcase_01 AC 127 ms
55,720 KB
testcase_02 AC 172 ms
56,208 KB
testcase_03 AC 126 ms
55,820 KB
testcase_04 AC 166 ms
56,484 KB
testcase_05 AC 127 ms
55,476 KB
testcase_06 AC 235 ms
57,820 KB
testcase_07 AC 259 ms
56,132 KB
testcase_08 WA -
testcase_09 AC 129 ms
55,976 KB
testcase_10 AC 126 ms
55,748 KB
testcase_11 AC 127 ms
55,504 KB
testcase_12 AC 128 ms
56,056 KB
testcase_13 AC 123 ms
55,788 KB
testcase_14 AC 126 ms
56,320 KB
testcase_15 AC 129 ms
55,880 KB
testcase_16 AC 124 ms
55,744 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 128 ms
56,164 KB
testcase_21 AC 270 ms
56,160 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 = 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);
	}
}
0