結果

問題 No.1463 Hungry Kanten
ユーザー threepipes_sthreepipes_s
提出日時 2021-04-02 21:47:29
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,879 bytes
コンパイル時間 2,611 ms
コンパイル使用メモリ 79,800 KB
実行使用メモリ 117,548 KB
最終ジャッジ日時 2024-06-06 09:18:32
合計ジャッジ時間 11,461 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,664 KB
testcase_01 AC 51 ms
36,576 KB
testcase_02 AC 230 ms
46,340 KB
testcase_03 AC 1,317 ms
60,088 KB
testcase_04 AC 55 ms
36,576 KB
testcase_05 TLE -
testcase_06 AC 53 ms
36,848 KB
testcase_07 AC 54 ms
37,088 KB
testcase_08 AC 57 ms
37,212 KB
testcase_09 AC 54 ms
36,580 KB
testcase_10 AC 75 ms
38,316 KB
testcase_11 AC 95 ms
39,004 KB
testcase_12 AC 119 ms
40,288 KB
testcase_13 AC 88 ms
38,368 KB
testcase_14 AC 164 ms
44,592 KB
testcase_15 AC 109 ms
39,900 KB
testcase_16 AC 229 ms
46,660 KB
testcase_17 AC 353 ms
53,864 KB
testcase_18 AC 222 ms
45,884 KB
testcase_19 AC 1,067 ms
81,552 KB
testcase_20 AC 1,413 ms
87,488 KB
testcase_21 AC 81 ms
39,168 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