結果

問題 No.1767 BLUE to RED
ユーザー 👑 kakel-sankakel-san
提出日時 2021-11-26 23:43:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,566 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 66,284 KB
実行使用メモリ 59,608 KB
最終ジャッジ日時 2023-09-12 05:39:30
合計ジャッジ時間 7,584 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,904 KB
testcase_01 AC 64 ms
21,756 KB
testcase_02 AC 65 ms
23,812 KB
testcase_03 AC 64 ms
19,848 KB
testcase_04 AC 74 ms
19,892 KB
testcase_05 AC 74 ms
23,948 KB
testcase_06 AC 65 ms
21,752 KB
testcase_07 AC 72 ms
23,988 KB
testcase_08 AC 74 ms
21,896 KB
testcase_09 AC 188 ms
45,232 KB
testcase_10 AC 221 ms
50,084 KB
testcase_11 AC 199 ms
41,900 KB
testcase_12 AC 190 ms
47,108 KB
testcase_13 AC 235 ms
49,648 KB
testcase_14 AC 277 ms
57,576 KB
testcase_15 AC 278 ms
59,568 KB
testcase_16 AC 278 ms
55,496 KB
testcase_17 AC 276 ms
59,608 KB
testcase_18 AC 276 ms
57,596 KB
testcase_19 AC 279 ms
57,652 KB
testcase_20 AC 279 ms
59,528 KB
testcase_21 AC 277 ms
57,484 KB
testcase_22 AC 279 ms
59,596 KB
testcase_23 AC 282 ms
59,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki325
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        var b = new Queue<int>(NList);

        var res = Math.Max(0, a[0] - b.Peek());
        while (b.Peek() < a[0]) b.Dequeue();

        for (var i = 1; i < a.Length; ++i)
        {
            var list = new List<int>();
            while (b.Count > 0 && b.Peek() < a[i]) list.Add(b.Dequeue());
            if (list.Count == 0) continue;
            if (list.Count == 1)
            {
                res += Math.Min(list[0] - a[i - 1], a[i] - list[0]);
                continue;
            }
            list.Insert(0, a[i - 1]);
            list.Add(a[i]);
            var sub = 0;
            for (var d = 0; d < list.Count - 1; ++d)
            {
                sub = Math.Max(sub, list[d + 1] - list[d]);
            }
            res += a[i] - a[i - 1] - sub;
        }

        if (b.Count > 0) res += Math.Max(0, b.Last() - a.Last());
        WriteLine(res);
    }
    static void DebugTable<T>(T[][] table)
    {
        Console.WriteLine("{");
        foreach (var list in table) Console.WriteLine(string.Join(", ", list));
        Console.WriteLine("}");
    }
}
0