結果

問題 No.1701 half price
ユーザー merlinmerlin
提出日時 2021-10-08 22:03:30
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,262 ms / 3,000 ms
コード長 952 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 54,028 KB
最終ジャッジ日時 2023-09-30 10:13:07
合計ジャッジ時間 7,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,500 KB
testcase_01 AC 43 ms
49,464 KB
testcase_02 AC 153 ms
52,968 KB
testcase_03 AC 44 ms
49,788 KB
testcase_04 AC 119 ms
51,600 KB
testcase_05 AC 47 ms
49,192 KB
testcase_06 AC 1,262 ms
51,376 KB
testcase_07 AC 1,042 ms
54,028 KB
testcase_08 AC 44 ms
49,356 KB
testcase_09 AC 44 ms
49,568 KB
testcase_10 AC 44 ms
49,388 KB
testcase_11 AC 44 ms
49,236 KB
testcase_12 AC 44 ms
49,388 KB
testcase_13 AC 44 ms
49,296 KB
testcase_14 AC 44 ms
49,404 KB
testcase_15 AC 44 ms
49,588 KB
testcase_16 AC 44 ms
47,440 KB
testcase_17 AC 46 ms
49,500 KB
testcase_18 AC 45 ms
49,544 KB
testcase_19 AC 45 ms
49,384 KB
testcase_20 AC 45 ms
49,392 KB
testcase_21 AC 895 ms
51,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),w=Integer.parseInt(s[1]);
        int i,j,k,ans=0,m=1<<n,a[]=new int[n];
        s=bu.readLine().split(" ");
        for(i=0;i<n;i++) a[i]=Integer.parseInt(s[i]);

        for(i=1;i<m;i++)
        for(j=0;j<m;j++)
        {
            long wt=0;
            for(k=0;k<n;k++)
            {
                int b1=(i>>k)&1,b2=(j>>k)&1;
                if(b1==0 && b2==1) {wt=-1; break;}
                if(b1==1)
                {
                    if(b2==0) wt+=a[k];
                    else wt+=a[k]/2;
                }
            }
            if(wt==w) {ans++; break;}
        }
        System.out.println(ans);
    }
}
0