結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
mencotton
|
| 提出日時 | 2018-02-19 22:59:34 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 794 bytes |
| コンパイル時間 | 814 ms |
| コンパイル使用メモリ | 110,088 KB |
| 実行使用メモリ | 27,856 KB |
| 最終ジャッジ日時 | 2024-07-16 03:51:55 |
| 合計ジャッジ時間 | 2,590 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 24 WA * 6 |
コンパイルメッセージ
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[n - 1]);
}
}
}
}
mencotton