結果

問題 No.3760 Streaming Schedule
コンテスト
ユーザー tobisatis
提出日時 2026-10-09 22:54:05
言語 C#
(.NET 10.0.400 + ACL)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 117 ms / 2,000 ms
+ 645µs
コード長 2,862 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,955 ms
コンパイル使用メモリ 170,876 KB
実行使用メモリ 91,204 KB
最終ジャッジ日時 2026-10-09 22:54:27
合計ジャッジ時間 11,094 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (262 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

#nullable enable

#region
var (_input, _iter) = (Array.Empty<string>(), 0);
T I<T>() where T : IParsable<T>
{
    while (_iter >= _input.Length) (_input, _iter) = (Console.ReadLine()!.Split(' ', StringSplitOptions.RemoveEmptyEntries), 0);
    return T.Parse(_input[_iter++], null);
}
#endregion

var n = I<int>();
var b = Math.Min(I<int>(), 3);
var c = I<int>();
var az = Enumerable.Range(0, n).Select(_ => I<int>()).ToArray();
var s = 0L;
foreach (var a in az) s += a;
var op = new Op();
var dp = new SegmentTree<long, Op>([.. Enumerable.Range(0, n + 1).Select(_ => op.IdentityElement)], op);
dp.Set(0, 0);
dp.Set(1, az[0]);
long last = az[0];
var suc = last;
for (var i = 2; i <= n; i++)
{
    var a = az[i - 1];
    var min = dp.Product(Math.Max(0, i - c), i - 1);
    dp.Set(i, min + a);
    if (b > 2) dp.Set(i - 1, Math.Min(suc, dp.Product(i - 1, i)));
    suc = last + a;
    last = min + a;
}
var ans = s - dp.Product(n + 1 - c, n + 1);
Console.WriteLine(ans);

readonly struct Op : ISegmentTreeOperator<long>
{
    public long IdentityElement => long.MaxValue / 8;
    public long Operation(long x, long y) => long.Min(x, y);
}
interface ISegmentTreeOperator<TMonoid>
{
    TMonoid IdentityElement { get; }
    TMonoid Operation(TMonoid x, TMonoid y);
}
class SegmentTree<TMonoid, TOperator> where TOperator : struct, ISegmentTreeOperator<TMonoid>
{
    public int BaseSize { get; protected init; }
    protected int Height { get; init; }
    protected TOperator Op { get; init; }
    protected TMonoid[] Values { get; init; }

    public SegmentTree(TMonoid[] initial, TOperator op = default)
    {
        Op = op;
        (BaseSize, Height) = (1, 0);
        while (BaseSize < initial.Length) (BaseSize, Height) = (BaseSize << 1, Height + 1);
        var size = BaseSize << 1;
        Values = new TMonoid[size];
        var values = Values;
        for (var i = 0; i < size; i++) values[i] = op.IdentityElement;
        for (var i = 0; i < initial.Length; i++) values[i + BaseSize] = initial[i];
        for (var i = BaseSize - 1; i > 0; i--) Update(values, i);
    }

    public TMonoid Product(int l, int r)
    {
        (l, r) = (l + BaseSize, r + BaseSize);
        var (resL, resR) = (Op.IdentityElement, Op.IdentityElement);
        var values = Values;
        while (l < r)
        {
            if ((l & 1) == 1) resL = Op.Operation(resL, values[l++]);
            if ((r & 1) == 1) resR = Op.Operation(values[--r], resR);
            (l, r) = (l >> 1, r >> 1);
        }
        return Op.Operation(resL, resR);
    }

    public void Set(int index, TMonoid value)
    {
        var j = index + BaseSize;
        var values = Values;
        values[j] = value;
        while ((j >>= 1) > 0) Update(values, j);
    }

    protected void Update(TMonoid[] values, int k) { values[k] = Op.Operation(values[k << 1], values[(k << 1) + 1]); }
}
0