結果

問題 No.45 回転寿司
ユーザー MoonOnRainMoonOnRain
提出日時 2018-05-21 21:40:51
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,652 bytes
コンパイル時間 3,702 ms
コンパイル使用メモリ 107,396 KB
実行使用メモリ 30,208 KB
最終ジャッジ日時 2023-09-11 01:05:03
合計ジャッジ時間 6,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 67 ms
21,776 KB
testcase_23 AC 68 ms
23,832 KB
testcase_24 AC 69 ms
23,756 KB
testcase_25 AC 66 ms
21,720 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 66 ms
19,952 KB
testcase_32 AC 67 ms
21,688 KB
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

public class Amatsuki
{
    private static List<int> sushiList;

    public static void Main()
    {
        Console.ReadLine();
        sushiList = Console.ReadLine().Split(new char[] {' '}).Select(x => int.Parse(x)).ToList();
        sushiList.Add(0);
        var eatenSushi = 0;

        do
        {
            eatenSushi += ChoiseSushi();
        } while (sushiList.Sum() != 0);

        Console.WriteLine(eatenSushi);
        Console.ReadKey();
    }

    private static int ChoiseSushi()
    {
        var deliciousSushiIndex = sushiList
            .Select((x, i) => new { Index = i, Sushi = x })
            .OrderByDescending(x => x.Sushi)
            .First()
            .Index;

        if (CompareSushi(deliciousSushiIndex))
        {
            return EatSushi(deliciousSushiIndex - 1) + EatSushi(deliciousSushiIndex + 1);
        }
        else
        {
            return EatSushi(deliciousSushiIndex);
        }
    }

    private static int EatSushi(int index)
    {
        var tmp = sushiList[index];
        sushiList[index] = 0;

        if (index + 1 < sushiList.Count)
        {
            sushiList[index + 1] = 0;
        }

        if (index != 0)
        {
            sushiList[index - 1] = 0;
        }

        return tmp;
    }

    private static bool CompareSushi(int index)
    {
        var comp = 0;

        if (index + 1 < sushiList.Count)
        {
            comp += sushiList[index + 1];
        }

        if (index != 0)
        {
            comp += sushiList[index - 1];
        }

        return (comp > sushiList[index]) ;
    }
}
0