結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | さかぽん |
提出日時 | 2021-02-18 15:18:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,071 bytes |
コンパイル時間 | 3,854 ms |
コンパイル使用メモリ | 104,536 KB |
実行使用メモリ | 49,852 KB |
最終ジャッジ日時 | 2023-10-12 23:30:27 |
合計ジャッジ時間 | 6,326 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
23,576 KB |
testcase_01 | AC | 65 ms
21,696 KB |
testcase_02 | AC | 122 ms
25,780 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 181 ms
49,852 KB |
testcase_06 | AC | 181 ms
49,832 KB |
testcase_07 | AC | 177 ms
48,312 KB |
testcase_08 | AC | 182 ms
49,744 KB |
testcase_09 | AC | 172 ms
45,432 KB |
testcase_10 | AC | 174 ms
43,500 KB |
testcase_11 | AC | 175 ms
43,508 KB |
testcase_12 | AC | 172 ms
43,496 KB |
testcase_13 | AC | 173 ms
45,580 KB |
testcase_14 | AC | 172 ms
43,696 KB |
testcase_15 | AC | 172 ms
43,476 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 < 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]; 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]); }