結果

問題 No.1463 Hungry Kanten
ユーザー bluemeganebluemegane
提出日時 2021-04-17 09:38:39
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,397 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 65,504 KB
実行使用メモリ 32,972 KB
最終ジャッジ日時 2023-09-16 15:32:48
合計ジャッジ時間 4,918 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
24,344 KB
testcase_01 AC 62 ms
24,436 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 127 ms
32,972 KB
testcase_06 AC 62 ms
24,360 KB
testcase_07 AC 62 ms
24,352 KB
testcase_08 AC 63 ms
24,348 KB
testcase_09 AC 60 ms
20,356 KB
testcase_10 AC 63 ms
22,284 KB
testcase_11 AC 64 ms
22,464 KB
testcase_12 AC 62 ms
22,324 KB
testcase_13 AC 62 ms
22,292 KB
testcase_14 AC 62 ms
22,304 KB
testcase_15 AC 62 ms
22,380 KB
testcase_16 AC 64 ms
20,404 KB
testcase_17 AC 70 ms
23,196 KB
testcase_18 AC 64 ms
22,360 KB
testcase_19 AC 93 ms
27,228 KB
testcase_20 AC 105 ms
32,908 KB
testcase_21 AC 62 ms
22,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAn(n, k, a);
    }
    static void getAn(int n, int k, int[] a)
    {
        var hs = new HashSet<long>();
        var imax = 1 << n;
        for (int i = 0; i < imax; i++)
        {
            if (countbit(i) >= k)
            {
                var s1 = 0;
                var s2 = 1L;
                for (int j = 0; j < n; j++)
                {
                    if (((i >> j) & 1) == 1)
                    {
                        s1 += a[j];
                        s2 *= a[j];
                    }
                }
                hs.Add(s1);
                hs.Add(s2);
            }
        }
        Console.WriteLine(hs.Count());
    }
    static int countbit(long bits)
    {
        bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
        bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
        bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
        bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
        return (int)(bits & 0x0000ffff) + (int)(bits >> 16 & 0x0000ffff);
    }
}
0