結果

問題 No.1825 Except One
ユーザー 👑 kakel-sankakel-san
提出日時 2023-12-18 23:21:56
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 1,302 ms / 3,000 ms
コード長 2,791 bytes
コンパイル時間 15,100 ms
コンパイル使用メモリ 158,056 KB
実行使用メモリ 403,084 KB
最終ジャッジ日時 2023-12-18 23:22:24
合計ジャッジ時間 27,180 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
32,932 KB
testcase_01 AC 83 ms
32,932 KB
testcase_02 AC 80 ms
32,932 KB
testcase_03 AC 738 ms
143,012 KB
testcase_04 AC 240 ms
78,628 KB
testcase_05 AC 133 ms
51,620 KB
testcase_06 AC 88 ms
35,876 KB
testcase_07 AC 761 ms
138,148 KB
testcase_08 AC 713 ms
141,604 KB
testcase_09 AC 88 ms
35,620 KB
testcase_10 AC 442 ms
113,060 KB
testcase_11 AC 153 ms
55,588 KB
testcase_12 AC 277 ms
87,160 KB
testcase_13 AC 180 ms
66,212 KB
testcase_14 AC 83 ms
33,444 KB
testcase_15 AC 86 ms
34,596 KB
testcase_16 AC 86 ms
35,108 KB
testcase_17 AC 83 ms
33,700 KB
testcase_18 AC 82 ms
33,060 KB
testcase_19 AC 83 ms
34,084 KB
testcase_20 AC 98 ms
33,700 KB
testcase_21 AC 81 ms
33,700 KB
testcase_22 AC 82 ms
33,700 KB
testcase_23 AC 83 ms
34,084 KB
testcase_24 AC 133 ms
52,772 KB
testcase_25 AC 100 ms
38,692 KB
testcase_26 AC 86 ms
33,956 KB
testcase_27 AC 233 ms
71,380 KB
testcase_28 AC 1,021 ms
198,052 KB
testcase_29 AC 94 ms
38,948 KB
testcase_30 AC 92 ms
36,132 KB
testcase_31 AC 125 ms
50,212 KB
testcase_32 AC 847 ms
156,452 KB
testcase_33 AC 94 ms
38,820 KB
testcase_34 AC 1,302 ms
403,084 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (217 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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        WriteLine(Except(n, a));
    }
    static long Except(int n, int[] _a)
    {
        var a = _a.ToArray();
        Array.Sort(a);
        var sum = a.Sum();
        var max = a[^1];
        var dp = new FenwickTree[n + 1][];
        for (var i = 0; i < dp.Length; ++i)
        {
            dp[i] = new FenwickTree[sum + 1];
            for (var j = 0; j < dp[i].Length; ++j) dp[i][j] = new FenwickTree(max + 1);
        }
        dp[0][0].Add(0, 1);
        for (var u = 0; u < n; ++u)
        {
            for (var i = u; i >= 0; --i) for (var j = sum; j >= 0; --j)
            {
                if (j + a[u] <= sum) dp[i + 1][j + a[u]].Add(a[u], dp[i][j].Sum(a[u]));
            }
        }
        var ans = 0L;
        for (var i = 2; i < dp.Length; ++i) for (var j = 0; j < dp[i].Length; ++j) for (var k = 0; k <= max; ++k)
        {
            if (j % (i - 1) == 0 && k <= j / (i - 1)) ans += dp[i][j].Get(k);
        }
        return ans;
    }
    class FenwickTree
    {
        int size;
        long[] tree;
        public FenwickTree(int size)
        {
            this.size = size;
            tree = new long[size + 2];
        }
        public void Add(int index, long value)
        {
            ++index;
            for (var x = index; x <= size; x += (x & -x)) tree[x] += value;
        }
        /// <summary>先頭からindexまでの和(include index)</summary>
        public long Sum(int index)
        {
            if (index < 0) return 0;
            ++index;
            var sum = 0L;
            for (var x = index; x > 0; x -= (x & -x)) sum += tree[x];
            return sum;
        }
        /// <summary>Sum(x) >= value となる最小のxを求める</summary>
        // 各要素は非負であること
        public int LowerBound(long value)
        {
            if (value < 0) return -1;
            var x = 0;
            var b = 1;
            while (b * 2 <= size) b <<= 1;
            for (var k = b; k > 0; k >>= 1)
            {
                if (x + k <= size && tree[x + k] < value)
                {
                    value -= tree[x + k];
                    x += k;
                }
            }
            return x;
        }
        public long Get(int index)
        {
            return index == 0 ? Sum(0) : (Sum(index) - Sum(index - 1));
        }
    }
}
0