結果

問題 No.1463 Hungry Kanten
ユーザー threepipes_sthreepipes_s
提出日時 2021-04-02 21:47:29
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,879 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 76,988 KB
実行使用メモリ 119,184 KB
最終ジャッジ日時 2023-08-25 14:55:45
合計ジャッジ時間 12,032 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,512 KB
testcase_01 AC 45 ms
49,568 KB
testcase_02 AC 232 ms
56,780 KB
testcase_03 AC 1,308 ms
71,860 KB
testcase_04 AC 48 ms
49,552 KB
testcase_05 TLE -
testcase_06 AC 46 ms
49,696 KB
testcase_07 AC 47 ms
49,548 KB
testcase_08 AC 51 ms
49,844 KB
testcase_09 AC 47 ms
49,768 KB
testcase_10 AC 66 ms
52,088 KB
testcase_11 AC 77 ms
50,480 KB
testcase_12 AC 102 ms
52,592 KB
testcase_13 AC 76 ms
52,084 KB
testcase_14 AC 157 ms
56,992 KB
testcase_15 AC 89 ms
50,024 KB
testcase_16 AC 230 ms
57,092 KB
testcase_17 AC 385 ms
64,748 KB
testcase_18 AC 217 ms
56,716 KB
testcase_19 AC 1,172 ms
92,040 KB
testcase_20 AC 1,584 ms
100,016 KB
testcase_21 AC 88 ms
50,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static ContestScanner in;static Writer out;static StringBuilder sb=new StringBuilder();
    public static void main(String[] args)
    {try{in=new ContestScanner();out=new Writer();Main solve=new Main();solve.solve();
        in.close();out.flush();out.close();}catch(IOException e){e.printStackTrace();}}
    void solve() throws NumberFormatException, IOException{
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        final int max = 1 << n;
        HashSet<String> multset = new HashSet<>();
        for (int i = 0; i < max; i++) {
            if (Integer.bitCount(i) < k) continue;
            int sum = 0;
            BigInteger bi = new BigInteger("1");
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) continue;
                sum += a[j];
                bi = bi.multiply(new BigInteger(String.valueOf(a[j])));
            }
            multset.add(String.valueOf(sum));
            multset.add(bi.toString());
        }
        System.out.println(multset.size());
    }
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}
0