結果

問題 No.45 回転寿司
ユーザー yuki2006yuki2006
提出日時 2018-01-29 13:36:25
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,633 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 100,968 KB
実行使用メモリ 24,220 KB
最終ジャッジ日時 2023-08-28 15:19:16
合計ジャッジ時間 14,556 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace lecture
{
    class MainClass
    {
        // 再帰関数
        // 戻り値として候補の最大値を取得する。
        // 寿司の美味しさ(A)と現在食べる場所(current)を引数にする
        public static int recursive(int[] A, int current)
        {
            int point = A[current];
            int P1 = 0;
            int P2 = 0;
            // 2つ先を食べる
            if (current + 2 < A.Length)
            {
                P1 = recursive(A, current + 2);
            }
            // 3つ先を食べるか
            if (current + 3 < A.Length)
            {
                P2 = recursive(A, current + 3);
            }
            if (P1 > P2)
            {
                return point + P1;
            }
            else
            {
                return point + P2;
            }
        }

        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] A = new int[N];
            string[] row = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(row[i]);
            }
            int P1 = 0;

            P1 = recursive(A, 0);

            int P2 = 0;
            // 2皿以上ある場合
            if (A.Length > 1)
            {
                P2 = recursive(A, 1);
            }

            if (P1 > P2)
            {
                Console.WriteLine(P1);
            }
            else
            {
                Console.WriteLine(P2);
            }
        }
    }
}
0