結果
| 問題 | 
                            No.1463 Hungry Kanten
                             | 
                    
| コンテスト | |
| ユーザー | 
                             threepipes_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 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 19 TLE * 1 | 
ソースコード
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();}
}
            
            
            
        
            
threepipes_s