結果

問題 No.1929 Exponential Sequence
ユーザー 👑 kakel-sankakel-san
提出日時 2023-10-24 23:40:50
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,696 ms / 2,000 ms
コード長 2,067 bytes
コンパイル時間 7,622 ms
コンパイル使用メモリ 158,424 KB
実行使用メモリ 177,396 KB
最終ジャッジ日時 2023-10-24 23:41:47
合計ジャッジ時間 21,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
32,720 KB
testcase_01 AC 81 ms
32,540 KB
testcase_02 AC 83 ms
32,708 KB
testcase_03 AC 1,696 ms
43,084 KB
testcase_04 AC 82 ms
32,712 KB
testcase_05 AC 82 ms
32,708 KB
testcase_06 AC 80 ms
32,716 KB
testcase_07 AC 82 ms
32,712 KB
testcase_08 AC 80 ms
32,708 KB
testcase_09 AC 81 ms
32,536 KB
testcase_10 AC 77 ms
32,536 KB
testcase_11 AC 82 ms
32,540 KB
testcase_12 AC 79 ms
32,536 KB
testcase_13 AC 79 ms
32,536 KB
testcase_14 AC 79 ms
32,540 KB
testcase_15 AC 89 ms
33,060 KB
testcase_16 AC 84 ms
32,720 KB
testcase_17 AC 84 ms
32,728 KB
testcase_18 AC 82 ms
32,704 KB
testcase_19 AC 82 ms
32,712 KB
testcase_20 AC 84 ms
32,704 KB
testcase_21 AC 1,645 ms
43,024 KB
testcase_22 AC 1,109 ms
39,180 KB
testcase_23 AC 1,625 ms
42,960 KB
testcase_24 AC 779 ms
38,016 KB
testcase_25 AC 1,596 ms
42,896 KB
testcase_26 AC 1,657 ms
43,100 KB
testcase_27 AC 86 ms
177,396 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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, s) = (c[0], c[1]);
        var a = NList;
        var fh = GetList(s, a.Take(n / 2).ToList());
        var sh = GetList(s, a.Skip(n / 2).ToList());
        fh.Sort();
        sh.Sort();
        var pos = sh.Count - 1;
        var ans = 0L;
        for (var i = 0; i < fh.Count; ++i)
        {
            while (pos >= 0 && fh[i] + sh[pos] > s) --pos;
            ans += pos + 1;
        }
        WriteLine(ans);
    }
    static List<int> GetList(int s, List<int> a)
    {
        var ans = new List<int>();
        if (a.Count == 0)
        {
            ans.Add(0);
            return ans;
        }
        var len = new List<int>[a.Count];
        for (var i = 0; i < len.Length; ++i)
        {
            len[i] = new List<int>();
            len[i].Add(1);
            var tmp = 1L;
            while (tmp * a[i] <= s)
            {
                len[i].Add((int)tmp * a[i]);
                tmp *= a[i];
            }
        }
        var bitmax = 1;
        foreach (var li in len) bitmax *= li.Count;
        for (var b = 1; b < bitmax; ++b)
        {
            var tmp = b;
            var flg = true;
            var sum = 0L;
            for (var i = 0; i < len.Length; ++i)
            {
                if (tmp % len[i].Count == 0)
                {
                    flg = false;
                    break;
                }
                sum += len[i][tmp % len[i].Count];
                tmp /= len[i].Count;
            }
            if (flg && sum <= s) ans.Add((int)sum);
        }
        return ans;
    }
}
0