結果

問題 No.968 引き算をして門松列(その3)
コンテスト
ユーザー kakel-san
提出日時 2025-12-15 23:55:14
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 2,058 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,331 ms
コンパイル使用メモリ 170,316 KB
実行使用メモリ 195,892 KB
最終ジャッジ日時 2025-12-15 23:55:26
合計ジャッジ時間 10,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (126 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #
raw source code

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Intrinsics.Arm;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var t = NN;
        var ans = new long[t];
        for (var i = 0; i < t; ++i)
        {
            var c = NList;
            ans[i] = Kado(c[0], c[1], c[2], c[3], c[4], c[5]);
        }
        WriteLine(string.Join("\n", ans));
    }
    static long Kado(int a, int b, int c, long x, long y, long z)
    {
        var ans = Math.Min(LHL(a, b, c, x, y, z), HLH(a, b, c, x, y, z));
        return ans == INF ? -1 : ans;
    }
    static long LHL(int a, int b, int c, long x, long y, long z)
    {
        if (a == c && a == 1) return INF;
        if (b < 3) return INF;
        var ans = INF;
        var zcnt = Math.Max(0, Math.Max(a, c) - b + 1 + (a == c ? 1 : 0));
        var la = a - zcnt;
        var lc = c - zcnt;
        if (la == lc)
        {
            if (la > 1) ans = Math.Min(ans, zcnt * z + Math.Min(x, y));
        }
        else
        {
            if (la > 0 && lc > 0) ans = Math.Min(ans, zcnt * z);
        }
        return ans;
    }
    static long HLH(int a, int b, int c, long x, long y, long z)
    {
        var ans = INF;
        var xcnt = Math.Max(0, b - c + 1);
        var ycnt = Math.Max(0, b - a + 1);
        var la = a - xcnt;
        var lb = b - xcnt - ycnt;
        var lc = c - ycnt;
        if (la == lc)
        {
            if (lb > 1) ans = Math.Min(ans, xcnt * x + ycnt * y + Math.Min(x, y));
        }
        else
        {
            if (lb > 0) ans = Math.Min(ans, xcnt * x + ycnt * y);
        }
        return ans;
    }
    static long INF = long.MaxValue / 2;
}
0