結果

問題 No.1463 Hungry Kanten
ユーザー threepipes_sthreepipes_s
提出日時 2021-04-02 21:47:29
言語 Java
(openjdk 23)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,879 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 79,660 KB
実行使用メモリ 99,616 KB
最終ジャッジ日時 2024-12-23 23:29:12
合計ジャッジ時間 12,314 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
50,628 KB
testcase_01 AC 50 ms
50,128 KB
testcase_02 AC 230 ms
57,456 KB
testcase_03 AC 1,687 ms
71,944 KB
testcase_04 AC 67 ms
50,416 KB
testcase_05 TLE -
testcase_06 AC 55 ms
50,532 KB
testcase_07 AC 54 ms
50,176 KB
testcase_08 AC 58 ms
50,404 KB
testcase_09 AC 55 ms
50,484 KB
testcase_10 AC 80 ms
51,368 KB
testcase_11 AC 93 ms
51,948 KB
testcase_12 AC 119 ms
52,600 KB
testcase_13 AC 92 ms
51,728 KB
testcase_14 AC 166 ms
56,880 KB
testcase_15 AC 110 ms
52,108 KB
testcase_16 AC 237 ms
56,572 KB
testcase_17 AC 367 ms
64,648 KB
testcase_18 AC 215 ms
57,296 KB
testcase_19 AC 1,109 ms
91,768 KB
testcase_20 AC 1,478 ms
99,616 KB
testcase_21 AC 95 ms
51,816 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