結果

問題 No.1701 half price
ユーザー harurunharurun
提出日時 2021-02-22 02:25:02
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 77,776 KB
実行使用メモリ 59,188 KB
最終ジャッジ日時 2023-09-30 09:22:36
合計ジャッジ時間 7,577 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
56,028 KB
testcase_01 AC 125 ms
55,740 KB
testcase_02 AC 261 ms
59,028 KB
testcase_03 AC 121 ms
55,976 KB
testcase_04 AC 261 ms
58,972 KB
testcase_05 AC 131 ms
56,036 KB
testcase_06 AC 773 ms
58,872 KB
testcase_07 AC 774 ms
59,188 KB
testcase_08 AC 120 ms
55,608 KB
testcase_09 AC 123 ms
56,324 KB
testcase_10 AC 118 ms
55,892 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 118 ms
55,668 KB
testcase_16 AC 117 ms
55,672 KB
testcase_17 AC 119 ms
55,768 KB
testcase_18 AC 117 ms
55,620 KB
testcase_19 AC 119 ms
56,172 KB
testcase_20 AC 118 ms
55,788 KB
testcase_21 AC 117 ms
55,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashSet;
import java.lang.Math;
import java.lang.String;

class Main {
  public static void main(String[] args) {
    Scanner scan=new Scanner(System.in);
    int N,W,m,n,cnt=0,a;
    N=Integer.parseInt(scan.next());
    W=Integer.parseInt(scan.next());
  	ArrayList<Integer> A=new ArrayList<Integer>();
    for(int i=0;i<N;i++){
      a=Integer.parseInt(scan.next());
      if(a==0)cnt++;
      else A.add(a);
    }
  	if(W==0){
  	  System.out.println((int)Math.pow(2,cnt)-1);
  	  return;
  	}
    n=N-cnt;
    m=(int)Math.pow(3,n);
  	HashSet<Integer> ans=new HashSet<Integer>();
    for(int i=0;i<m;i++){
      long s=0;
      int b=0,x=1;
      String u=change(i,3);
      for(int j=0;j<u.length();j++){
      	if(u.charAt(j)=='1'){
      	  s+=A.get(j);
      	  b+=x;
      	}
      	else if(u.charAt(j)=='2'){
      	  s+=A.get(j)/2;
      	  b+=x;
      	}
      	x*=2;
      }
      if(s==W)ans.add(b);
    }
    System.out.println(ans.size());
  }
  private static String change(int n,int k){
    StringBuilder sb=new StringBuilder();
    while(n!=0){
      sb.append(String.valueOf(n%k));
      n/=k;
    }
    return sb.toString();
  }
}
0