結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-13 00:01:52 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 1,000 ms |
| コード長 | 4,082 bytes |
| コンパイル時間 | 2,542 ms |
| コンパイル使用メモリ | 109,956 KB |
| 実行使用メモリ | 25,992 KB |
| 最終ジャッジ日時 | 2024-10-13 00:02:13 |
| 合計ジャッジ時間 | 4,325 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
コンパイルメッセージ
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;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("1");
WillReturn.Add("3");
WillReturn.Add("3");
WillReturn.Add("4");
//1
//真ん中の竹に1度魔法を唱えることで。条件を満たすことができます
}
else if (InputPattern == "Input2") {
WillReturn.Add("411");
WillReturn.Add("4");
WillReturn.Add("1");
WillReturn.Add("5");
//0
//魔法を使う必要がないこともあります
}
else if (InputPattern == "Input3") {
WillReturn.Add("2");
WillReturn.Add("3");
WillReturn.Add("10");
WillReturn.Add("12");
//2
}
else if (InputPattern == "Input4") {
WillReturn.Add("1");
WillReturn.Add("0");
WillReturn.Add("0");
WillReturn.Add("0");
//-1
//魔法を使ってもどうしようもないこともあります
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static int D;
static void Main()
{
List<string> InputList = GetInputList();
D = int.Parse(InputList[0]);
int H1 = int.Parse(InputList[1]);
int H2 = int.Parse(InputList[2]);
int H3 = int.Parse(InputList[3]);
Console.WriteLine(DeriveAnswer(H1, H2, H3));
}
static int DeriveAnswer(int pH1, int pH2, int pH3)
{
int wkInt1 = DeriveMahouCnt1(pH1, pH2, pH3);
int wkInt2 = DeriveMahouCnt2(pH1, pH2, pH3);
if (wkInt1 == -1 && wkInt2 == -1) return -1;
if (wkInt1 == -1 && wkInt2 != -1) return wkInt2;
if (wkInt1 != -1 && wkInt2 == -1) return wkInt1;
return Math.Min(wkInt1, wkInt2);
}
//3本の竹全ての高さが互いに異なり、
//真ん中の竹の高さが一番高い状態にする
static int DeriveMahouCnt1(int pH1, int pH2, int pH3)
{
int MahouCnt = 0;
if (D > 0) {
if (pH2 <= pH1) {
int wkCnt = (pH1 - pH2) / D + 1;
ExecMahou(ref pH1, wkCnt);
MahouCnt += wkCnt;
}
if (pH2 <= pH3) {
int wkCnt = (pH3 - pH2) / D + 1;
ExecMahou(ref pH3, wkCnt);
MahouCnt += wkCnt;
}
if (pH1 == pH3) {
ExecMahou(ref pH1, 1);
MahouCnt++;
}
}
if (pH1 == pH2) return -1;
if (pH1 == pH3) return -1;
if (pH2 == pH3) return -1;
if (pH2 <= pH1) return -1;
if (pH2 <= pH3) return -1;
return MahouCnt;
}
//3本の竹全ての高さが互いに異なり、
//真ん中の竹の高さが一番低い状態にする
static int DeriveMahouCnt2(int pH1, int pH2, int pH3)
{
int MahouCnt = 0;
if (D > 0) {
if (pH1 == pH3) {
ExecMahou(ref pH1, 1);
MahouCnt++;
}
if (pH1 <= pH2) {
int wkCnt = (pH2 - pH1) / D + 1;
ExecMahou(ref pH2, wkCnt);
MahouCnt += wkCnt;
}
if (pH3 <= pH2) {
int wkCnt = (pH2 - pH3) / D + 1;
ExecMahou(ref pH2, wkCnt);
MahouCnt += wkCnt;
}
}
if (pH1 == pH2) return -1;
if (pH1 == pH3) return -1;
if (pH2 == pH3) return -1;
if (pH1 <= pH2) return -1;
if (pH3 <= pH2) return -1;
return MahouCnt;
}
//魔法をN回実行する
static void ExecMahou(ref int pTarget, int pN)
{
pTarget = Math.Max(0, pTarget - pN * D);
}
}
aketijyuuzou