結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー 👑 kakel-sankakel-san
提出日時 2024-06-10 23:03:41
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,569 bytes
コンパイル時間 14,151 ms
コンパイル使用メモリ 167,872 KB
実行使用メモリ 190,700 KB
最終ジャッジ日時 2024-06-10 23:04:00
合計ジャッジ時間 18,687 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
30,592 KB
testcase_01 AC 49 ms
30,464 KB
testcase_02 AC 48 ms
30,720 KB
testcase_03 AC 49 ms
30,848 KB
testcase_04 AC 50 ms
30,848 KB
testcase_05 AC 49 ms
30,848 KB
testcase_06 AC 50 ms
30,464 KB
testcase_07 AC 49 ms
30,336 KB
testcase_08 AC 49 ms
30,336 KB
testcase_09 AC 48 ms
30,720 KB
testcase_10 AC 54 ms
30,848 KB
testcase_11 AC 48 ms
30,592 KB
testcase_12 AC 49 ms
30,336 KB
testcase_13 AC 49 ms
30,972 KB
testcase_14 AC 53 ms
30,848 KB
testcase_15 AC 50 ms
30,720 KB
testcase_16 AC 51 ms
30,464 KB
testcase_17 AC 49 ms
30,712 KB
testcase_18 AC 49 ms
30,464 KB
testcase_19 AC 48 ms
30,592 KB
testcase_20 AC 48 ms
30,336 KB
testcase_21 AC 49 ms
30,720 KB
testcase_22 AC 50 ms
30,720 KB
testcase_23 AC 48 ms
30,720 KB
testcase_24 AC 49 ms
30,464 KB
testcase_25 AC 48 ms
30,464 KB
testcase_26 AC 49 ms
30,840 KB
testcase_27 AC 49 ms
30,976 KB
testcase_28 AC 49 ms
30,720 KB
testcase_29 AC 53 ms
30,336 KB
testcase_30 AC 51 ms
30,696 KB
testcase_31 AC 49 ms
30,720 KB
testcase_32 AC 49 ms
30,464 KB
testcase_33 AC 48 ms
30,208 KB
testcase_34 AC 49 ms
30,464 KB
testcase_35 AC 49 ms
30,592 KB
testcase_36 AC 48 ms
30,592 KB
testcase_37 AC 65 ms
31,104 KB
testcase_38 AC 67 ms
31,104 KB
testcase_39 AC 66 ms
31,232 KB
testcase_40 AC 57 ms
31,232 KB
testcase_41 AC 56 ms
31,616 KB
testcase_42 AC 68 ms
31,612 KB
testcase_43 AC 48 ms
30,464 KB
testcase_44 AC 62 ms
31,232 KB
testcase_45 AC 67 ms
31,104 KB
testcase_46 AC 68 ms
31,188 KB
testcase_47 AC 56 ms
32,128 KB
testcase_48 AC 59 ms
33,536 KB
testcase_49 AC 58 ms
31,360 KB
testcase_50 AC 49 ms
30,464 KB
testcase_51 AC 73 ms
33,912 KB
testcase_52 AC 64 ms
33,664 KB
testcase_53 AC 60 ms
33,664 KB
testcase_54 AC 71 ms
33,912 KB
testcase_55 AC 63 ms
33,784 KB
testcase_56 AC 72 ms
190,700 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (84 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, k) = (c[0], c[1]);
        var a = NList;
        YN(Make(n, k, a));
    }
    static bool Make(int n, int k, int[] a)
    {
        if (a.Contains(k)) return true;
        var first = new HashSet<long>[4];
        for (var i = 0; i < first.Length; ++i) first[i] = new HashSet<long>();
        var bitmax = (int)Math.Pow(3, n / 2);
        for (var b = 0; b < bitmax; ++b)
        {
            var sum = 0L;
            var tmp = b;
            var plus = false;
            var minus = false;
            for (var i = 0; i < n / 2; ++i)
            {
                sum += a[i] * (tmp % 3 - 1);
                if (tmp % 3 == 0) minus = true;
                if (tmp % 3 == 2) plus = true;
                tmp /= 3;
            }
            if (!plus && !minus) first[0].Add(sum);
            else if (!plus && minus) first[1].Add(sum);
            else if (plus && !minus) first[2].Add(sum);
            else first[3].Add(sum);
        }
        bitmax = (int)Math.Pow(3, n - n / 2);
        for (var b = 0; b < bitmax; ++b)
        {
            var sum = 0L;
            var tmp = b;
            var plus = false;
            var minus = false;
            for (var i = 0; i < n - n / 2; ++i)
            {
                sum += a[i + n / 2] * (tmp % 3 - 1);
                if (tmp % 3 == 0) minus = true;
                if (tmp % 3 == 2) plus = true;
                tmp /= 3;
            }
            if (plus && minus)
            {
                if (first[0].Contains(k + sum) || first[0].Contains(sum - k)) return true;
            }
            if (plus)
            {
                if (first[2].Contains(k + sum) || first[2].Contains(sum - k)) return true;
            }
            if (minus)
            {
                if (first[1].Contains(k + sum) || first[1].Contains(sum - k)) return true;
            }
            if (first[3].Contains(k + sum) || first[3].Contains(sum - k)) return true;
        }
        return false;
    }
    static void YN(bool b)
    {
        WriteLine(b ? "Yes" : "No");
    }
}
0