結果

問題 No.45 回転寿司
ユーザー PoronPaPoronPa
提出日時 2019-05-18 23:57:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,282 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 107,520 KB
実行使用メモリ 23,860 KB
最終ジャッジ日時 2023-08-27 17:01:16
合計ジャッジ時間 5,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,692 KB
testcase_01 AC 60 ms
23,752 KB
testcase_02 AC 59 ms
23,684 KB
testcase_03 AC 57 ms
21,624 KB
testcase_04 AC 60 ms
21,624 KB
testcase_05 AC 54 ms
21,620 KB
testcase_06 AC 58 ms
21,812 KB
testcase_07 AC 57 ms
21,764 KB
testcase_08 AC 56 ms
21,832 KB
testcase_09 AC 59 ms
23,676 KB
testcase_10 AC 60 ms
21,680 KB
testcase_11 AC 56 ms
21,700 KB
testcase_12 AC 58 ms
21,712 KB
testcase_13 AC 56 ms
21,624 KB
testcase_14 AC 53 ms
21,524 KB
testcase_15 AC 60 ms
19,532 KB
testcase_16 AC 60 ms
21,724 KB
testcase_17 AC 60 ms
23,860 KB
testcase_18 AC 60 ms
23,720 KB
testcase_19 AC 60 ms
23,836 KB
testcase_20 AC 53 ms
21,496 KB
testcase_21 AC 52 ms
23,584 KB
testcase_22 AC 51 ms
21,668 KB
testcase_23 AC 53 ms
21,596 KB
testcase_24 AC 53 ms
21,716 KB
testcase_25 AC 53 ms
21,620 KB
testcase_26 AC 61 ms
21,860 KB
testcase_27 AC 61 ms
21,700 KB
testcase_28 AC 58 ms
23,680 KB
testcase_29 AC 59 ms
21,624 KB
testcase_30 AC 59 ms
21,716 KB
testcase_31 AC 54 ms
21,660 KB
testcase_32 AC 51 ms
21,548 KB
testcase_33 AC 59 ms
21,632 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 Program
{
    class Program
    {
        static void Main()
        {
            int count = int.Parse(Console.ReadLine());
            int[] aji = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Dp m_dp = new Dp(aji, count);
            Console.WriteLine(m_dp.GetMax().ToString());
            Console.ReadLine();
        }

    }
    class Dp
    {
        private int[,] _dp = new int[1000, 2];
        private int[] _aji;
        private int _saraCount;

        public Dp(int[] aji, int saracount)
        {
            _saraCount = saracount;
            _aji = aji;
            _dp[0, 0] = 0;
            _dp[0, 1] = _aji[0];
        }

        public int GetMax()
        {
            if (_saraCount == 1)
            {
                return _aji[0];
            }
            _dp[1, 0] = _dp[0, 1];
            _dp[1, 1] = _aji[1] + _dp[0, 0];

            for (int count = 2; count < _saraCount; count++)
            {
                _dp[count, 0] = Math.Max(_dp[count - 1, 1], _dp[count - 2, 1]);
                _dp[count, 1] = _aji[count] + Math.Max(_dp[count - 1, 0], _dp[count - 2, 0]);
            }
            return Math.Max(_dp[_saraCount - 1, 0], _dp[_saraCount - 1, 1]);
        }
    }
}
0