結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
keymoon
|
| 提出日時 | 2021-02-02 02:38:14 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 1,300 bytes |
| コンパイル時間 | 852 ms |
| コンパイル使用メモリ | 113,960 KB |
| 実行使用メモリ | 31,296 KB |
| 最終ジャッジ日時 | 2024-06-29 23:34:51 |
| 合計ジャッジ時間 | 1,824 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
コンパイルメッセージ
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;
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);
}
}
keymoon