結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | さかぽん |
提出日時 | 2021-02-18 11:08:37 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 203 ms / 2,000 ms |
コード長 | 1,071 bytes |
コンパイル時間 | 3,717 ms |
コンパイル使用メモリ | 104,248 KB |
実行使用メモリ | 49,832 KB |
最終ジャッジ日時 | 2023-10-12 19:49:31 |
合計ジャッジ時間 | 6,660 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
21,596 KB |
testcase_01 | AC | 66 ms
21,556 KB |
testcase_02 | AC | 137 ms
27,724 KB |
testcase_03 | AC | 81 ms
23,672 KB |
testcase_04 | AC | 92 ms
25,752 KB |
testcase_05 | AC | 198 ms
47,664 KB |
testcase_06 | AC | 197 ms
47,720 KB |
testcase_07 | AC | 192 ms
46,304 KB |
testcase_08 | AC | 203 ms
49,832 KB |
testcase_09 | AC | 195 ms
43,512 KB |
testcase_10 | AC | 196 ms
43,640 KB |
testcase_11 | AC | 198 ms
45,520 KB |
testcase_12 | AC | 196 ms
43,524 KB |
testcase_13 | AC | 196 ms
43,596 KB |
testcase_14 | AC | 196 ms
41,480 KB |
testcase_15 | AC | 197 ms
43,412 KB |
コンパイルメッセージ
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 < 5; 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]; dp[0] = p[0]; for (int i = 3; 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]); 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]); }