結果

問題 No.194 フィボナッチ数列の理解(1)
ユーザー agatanagatan
提出日時 2015-04-26 23:22:13
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 696 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 86,188 KB
実行使用メモリ 19,052 KB
最終ジャッジ日時 2023-09-02 20:17:05
合計ジャッジ時間 7,588 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 51 ms
16,512 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.array, std.stdio, std.string, std.algorithm, std.conv;
import std.range;

long[] fibmem;
long N, K;

void main()
{
    auto nk = readln.split.map!(to!long);
    N = nk[0]; K = nk[1];
    long[] A = readln.split.map!(to!long).array;
    fibmem.length = K+1;
    foreach(ref i; fibmem) i = -1;
    foreach(i, a; A) fibmem[i] = a;
    long f = fib(K-1) % (10 ^^9 + 7);
    long s = 0;
    foreach(i; 0..K) {
        s += fib(i) % (10 ^^ 9 + 7);
        s %= 10 ^^ 9 + 7;
    }
    writeln(f, ' ', s);
}

long fib(long n) {
    if (fibmem[n] != -1) return fibmem[n];
    long ret = 0;
    foreach_reverse (i; 1..N+1) {
        ret += fib(n-i);
    }
    fibmem[n] = ret;
    return ret;
}
0