結果

問題 No.45 回転寿司
ユーザー mencottonmencotton
提出日時 2018-02-19 23:01:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 793 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 102,704 KB
実行使用メモリ 23,920 KB
最終ジャッジ日時 2023-08-27 16:01:44
合計ジャッジ時間 5,059 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
23,872 KB
testcase_01 AC 58 ms
23,896 KB
testcase_02 AC 59 ms
21,752 KB
testcase_03 AC 63 ms
21,748 KB
testcase_04 AC 58 ms
19,720 KB
testcase_05 AC 54 ms
23,688 KB
testcase_06 AC 60 ms
21,884 KB
testcase_07 AC 62 ms
21,780 KB
testcase_08 AC 60 ms
21,836 KB
testcase_09 AC 62 ms
21,888 KB
testcase_10 AC 64 ms
19,792 KB
testcase_11 AC 61 ms
21,784 KB
testcase_12 AC 63 ms
21,892 KB
testcase_13 AC 57 ms
21,744 KB
testcase_14 AC 57 ms
21,648 KB
testcase_15 AC 63 ms
19,880 KB
testcase_16 AC 60 ms
23,920 KB
testcase_17 AC 60 ms
21,948 KB
testcase_18 AC 59 ms
21,824 KB
testcase_19 AC 60 ms
21,852 KB
testcase_20 AC 55 ms
21,644 KB
testcase_21 AC 53 ms
21,752 KB
testcase_22 AC 54 ms
21,692 KB
testcase_23 AC 53 ms
21,708 KB
testcase_24 AC 52 ms
21,652 KB
testcase_25 AC 51 ms
19,636 KB
testcase_26 AC 60 ms
23,820 KB
testcase_27 AC 61 ms
19,816 KB
testcase_28 AC 60 ms
21,764 KB
testcase_29 AC 67 ms
21,840 KB
testcase_30 AC 63 ms
21,760 KB
testcase_31 AC 52 ms
21,768 KB
testcase_32 AC 55 ms
23,820 KB
testcase_33 AC 61 ms
21,812 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

namespace _45
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (n == 1) Console.WriteLine(x[0]);
            else if (n == 2) Console.WriteLine(x.Max());
            else if (n == 3) Console.WriteLine(Math.Max(x[0] + x[2],x[1]));
            else
            {
                int[] dp = new int[n];
                dp[0] = x[0]; dp[1] = x[1]; dp[2] = dp[0] + x[2];
                for (int i = 3; i < n; i++)
                {
                    dp[i] = Math.Max(dp[i - 2],dp[i - 3]) + x[i];
                }
                Console.WriteLine(dp.Max());
            }
        }
    }
}
0