結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-18 15:21:13 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 1,071 bytes |
| コンパイル時間 | 893 ms |
| コンパイル使用メモリ | 114,084 KB |
| 実行使用メモリ | 45,440 KB |
| 最終ジャッジ日時 | 2024-09-14 21:37:34 |
| 合計ジャッジ時間 | 3,507 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 15 |
コンパイルメッセージ
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;
class C
{
static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Solve())));
static object Solve()
{
var n = int.Parse(Console.ReadLine());
var a = Read().ToList();
var r = 0L;
for (int i = 0; i < 3; i++)
{
r = Math.Max(r, GetMax(a.ToArray()));
a.Add(a[0]);
a.RemoveAt(0);
}
return r;
}
static long GetMax(int[] a)
{
var p = new long[a.Length];
for (int i = 0; i < a.Length - 2; i++)
if (IsKadomatsu(a, i)) p[i] = a[i];
var dp = new long[a.Length];
for (int i = 0; i < a.Length; i++)
{
var max = 0L;
if (i - 5 >= 0) max = Math.Max(max, dp[i - 5]);
if (i - 4 >= 0) max = Math.Max(max, dp[i - 4]);
if (i - 3 >= 0) max = Math.Max(max, dp[i - 3]);
dp[i] = max + p[i];
}
return dp.Max();
}
static bool IsKadomatsu(int[] a, int i) => a[i] != a[i + 2] && (a[i] < a[i + 1] && a[i + 1] > a[i + 2] || a[i] > a[i + 1] && a[i + 1] < a[i + 2]);
}