結果
| 問題 |
No.533 Mysterious Stairs
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-06-23 23:13:03 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 1,410 ms / 5,000 ms |
| コード長 | 1,699 bytes |
| コンパイル時間 | 979 ms |
| コンパイル使用メモリ | 105,856 KB |
| 実行使用メモリ | 179,172 KB |
| 最終ジャッジ日時 | 2024-10-04 07:59:45 |
| 合計ジャッジ時間 | 8,341 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc()
{
int stepCount = int.Parse(Reader.ReadLine());
for (int i = 1; i <= stepCount; i++) {
GetAns(0, i);
}
long ans = GetAns(0, stepCount);
Console.WriteLine(ans);
}
private long Mod = 1000000000 + 7;
private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>();
private long GetAns(int prevStep, int remain) {
if(remain == 0) {
return 1;
}
if(remain < 0) {
return 0;
}
if(!dic.ContainsKey(prevStep)) {
dic.Add(prevStep, new Dictionary<int, long>());
}
if(dic[prevStep].ContainsKey(remain)) {
return dic[prevStep][remain];
}
long ans = 0;
for (int i = 1; i <= 3; i++) {
if(i==prevStep) {
continue;
}
ans += GetAns(i, remain - i);
ans = ans % Mod;
}
dic[prevStep][remain] = ans;
return ans;
}
public class Reader
{
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine()
{
if (IsDebug)
{
if (sr == null)
{
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
private static string InputText = @"
49993
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
14番