結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | 14番 |
提出日時 | 2017-06-09 22:28:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,338 ms / 2,000 ms |
コード長 | 1,297 bytes |
コンパイル時間 | 2,041 ms |
コンパイル使用メモリ | 111,544 KB |
実行使用メモリ | 478,300 KB |
最終ジャッジ日時 | 2023-10-23 21:43:20 |
合計ジャッジ時間 | 8,764 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
25,468 KB |
testcase_01 | AC | 29 ms
25,468 KB |
testcase_02 | AC | 29 ms
25,468 KB |
testcase_03 | AC | 29 ms
25,468 KB |
testcase_04 | AC | 29 ms
25,468 KB |
testcase_05 | AC | 30 ms
25,468 KB |
testcase_06 | AC | 29 ms
25,468 KB |
testcase_07 | AC | 30 ms
25,508 KB |
testcase_08 | AC | 32 ms
25,928 KB |
testcase_09 | AC | 48 ms
36,124 KB |
testcase_10 | AC | 240 ms
119,800 KB |
testcase_11 | AC | 1,338 ms
476,940 KB |
testcase_12 | AC | 1,320 ms
478,300 KB |
testcase_13 | AC | 1,324 ms
478,300 KB |
testcase_14 | AC | 1,316 ms
478,300 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.IO; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int num = inpt[0]; this.Mod = inpt[1]; long ans = GetAns(num); Console.WriteLine(ans); } private Dictionary<int, long> dic = new Dictionary<int, long>(); private long GetAns(int num) { if(num <= 1) { return 0; } if(num == 2) { return 1; } if(dic.ContainsKey(num)) { return dic[num]; } long ans = (GetAns(num - 1) + GetAns(num - 2)) % Mod; dic[num] = ans; return ans; } private int Mod = 0; 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 = @" 10 20 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }