結果

問題 No.966 引き算をして門松列(その1)
ユーザー keymoonkeymoon
提出日時 2021-02-02 02:38:14
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 3,035 ms
コンパイル使用メモリ 103,844 KB
実行使用メモリ 28,100 KB
最終ジャッジ日時 2023-09-12 10:58:20
合計ジャッジ時間 3,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
19,856 KB
testcase_01 AC 65 ms
21,900 KB
testcase_02 AC 64 ms
21,964 KB
testcase_03 AC 64 ms
21,996 KB
testcase_04 AC 117 ms
28,040 KB
testcase_05 AC 120 ms
28,004 KB
testcase_06 AC 134 ms
28,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            Solve();
        }
    }
    static void Solve()
    {
        var abc = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var orders = new[]
        {
            new[] { 1, 0, 2 },
            new[] { 1, 2, 0 },
            new[] { 2, 0, 1 },
            new[] { 0, 2, 1 },
        };
        long min = long.MaxValue;
        foreach (var order in orders)
        {
            var vals = abc.ToArray();
            long res = 0;
            for (int i = 1; i < order.Length; i++)
            {
                var prev = order[i - 1];
                var cur = order[i];
                var sub = Max(vals[cur] - (vals[prev] - 1), 0);
                vals[cur] -= sub;
                res += sub;
            }
            if (1 <= vals.Min()) min = Min(min, res);
        }
        Console.WriteLine(min == long.MaxValue ? -1 : min);
    }
}
0