結果
| 問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-18 10:08:40 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 2,000 ms |
| コード長 | 878 bytes |
| コンパイル時間 | 1,182 ms |
| コンパイル使用メモリ | 118,044 KB |
| 実行使用メモリ | 290,432 KB |
| 最終ジャッジ日時 | 2024-10-08 06:01:09 |
| 合計ジャッジ時間 | 3,984 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
class B
{
static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
static void Main() => Console.WriteLine(Solve());
static object Solve()
{
var (n, m) = Read2();
var dp = new MemoDP1<long>(n, -1, (t, i) =>
{
return (t[i - 2] + t[i - 1]) % m;
});
dp[0] = 0;
dp[1] = 1;
return dp[n - 1];
}
}
class MemoDP1<T>
{
static readonly Func<T, T, bool> TEquals = System.Collections.Generic.EqualityComparer<T>.Default.Equals;
public T[] Raw { get; }
T iv;
Func<MemoDP1<T>, int, T> rec;
public MemoDP1(int n, T iv, Func<MemoDP1<T>, int, T> rec)
{
Raw = Array.ConvertAll(new bool[n], _ => iv);
this.iv = iv;
this.rec = rec;
}
public T this[int i]
{
get => TEquals(Raw[i], iv) ? Raw[i] = rec(this, i) : Raw[i];
set => Raw[i] = value;
}
}