結果
問題 |
No.45 回転寿司
|
ユーザー |
|
提出日時 | 2018-01-29 13:36:25 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,633 bytes |
コンパイル時間 | 3,003 ms |
コンパイル使用メモリ | 107,756 KB |
実行使用メモリ | 39,992 KB |
最終ジャッジ日時 | 2024-12-29 18:04:49 |
合計ジャッジ時間 | 170,008 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 TLE * 26 |
コンパイルメッセージ
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; 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); } } } }