結果

問題 No.1755 Almost Palindrome
ユーザー さかぽんさかぽん
提出日時 2021-11-22 11:53:41
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 2,663 ms
コンパイル使用メモリ 109,880 KB
実行使用メモリ 39,760 KB
最終ジャッジ日時 2023-09-06 03:09:43
合計ジャッジ時間 4,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
38,704 KB
testcase_01 AC 94 ms
36,616 KB
testcase_02 AC 166 ms
39,760 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;

class B
{
	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());

		if (dp == null) dp = Init();
		return dp[n];
	}

	static long[] dp;
	static long[] Init()
	{
		var n = 1000000;

		// 回文
		var p = new long[n + 1];
		p[0] = 1;
		p[1] = 26;
		for (int i = 2; i <= n; i++)
		{
			p[i] = p[i - 2] * 26 % M;
		}

		var dp = new long[n + 1];
		dp[2] = 25 * 26;

		for (int i = 3; i <= n; i++)
		{
			dp[i] = dp[i - 2] * 26 + p[i - 3] * 25 * 26 * 2;
			if (i % 2 == 0) dp[i] += M - 25 * 26;
			dp[i] %= M;
		}
		return dp;
	}

	const long M = 998244353;
}
0