結果
| 問題 |
No.1767 BLUE to RED
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-26 23:43:17 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 246 ms / 2,000 ms |
| コード長 | 1,566 bytes |
| コンパイル時間 | 1,306 ms |
| コンパイル使用メモリ | 108,672 KB |
| 実行使用メモリ | 56,304 KB |
| 最終ジャッジ日時 | 2024-06-29 18:38:34 |
| 合計ジャッジ時間 | 6,278 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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("}");
}
}