結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
mencotton
|
| 提出日時 | 2018-02-19 23:01:08 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 5,000 ms |
| コード長 | 793 bytes |
| コンパイル時間 | 1,023 ms |
| コンパイル使用メモリ | 104,832 KB |
| 実行使用メモリ | 19,456 KB |
| 最終ジャッジ日時 | 2024-12-27 18:00:15 |
| 合計ジャッジ時間 | 3,478 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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());
}
}
}
}
mencotton