結果
| 問題 |
No.1368 サイクルの中に眠る門松列
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2021-02-04 09:43:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,502 bytes |
| コンパイル時間 | 862 ms |
| コンパイル使用メモリ | 112,892 KB |
| 実行使用メモリ | 50,108 KB |
| 最終ジャッジ日時 | 2024-06-30 14:56:16 |
| 合計ジャッジ時間 | 4,038 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 WA * 3 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using static System.Math;
using System;
public class Hello
{
public static int[] a, b, c;
static void Main()
{
var q = int.Parse(Console.ReadLine().Trim());
while (q-- > 0)
{
var n = int.Parse(Console.ReadLine().Trim());
string[] line = Console.ReadLine().Trim().Split(' ');
a = new int[n];
b = new int[n];
c = new int[n];
for (int i = 0; i < n; i++)
{
var t = int.Parse(line[i]);
a[i] = t;
if (i - 1 >= 0) b[i - 1] = t;
if (i - 2 >= 0) c[i - 2] = t;
}
b[n - 1] = a[0]; c[n - 2] = a[0]; c[n - 1] = a[1];
var ans = Max(Dp(n, a), Dp(n, b));
ans = Max(ans, Dp(n, c));
Console.WriteLine(ans);
}
}
static int Dp(int n, int[] t)
{
var dp = new int[n];
var w = new int[3] { t[0], t[1], t[2] };
dp[2] = check(w) ? t[0] : 0;
for (int i = 3; i < n; i++)
{
if (check(new int[] { t[i - 2], t[i - 1], t[i] }))
dp[i] = Max(dp[i - 1], dp[i - 3] + t[i - 2]);
else dp[i] = dp[i - 1];
}
return dp[n - 1];
}
static bool check(int[] t)
{
if (!(t[0] != t[1] && t[1] != t[2] && t[0] != t[2])) return false;
if (t[1] > t[0] && t[1] > t[2]) return true;
if (t[1] < t[0] && t[1] < t[2]) return true;
return false;
}
}
bluemegane