結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2018-05-21 21:40:51 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,652 bytes |
コンパイル時間 | 933 ms |
コンパイル使用メモリ | 108,800 KB |
実行使用メモリ | 24,064 KB |
最終ジャッジ日時 | 2024-06-28 15:36:21 |
合計ジャッジ時間 | 3,287 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 WA * 28 |
コンパイルメッセージ
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 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]) ; } }