結果

問題 No.554 recurrence formula
ユーザー ebicochinealebicochineal
提出日時 2017-08-11 23:17:18
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 803 bytes
コンパイル時間 5,594 ms
コンパイル使用メモリ 105,024 KB
実行使用メモリ 23,620 KB
最終ジャッジ日時 2023-08-02 23:41:35
合計ジャッジ時間 12,647 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,696 KB
testcase_01 AC 54 ms
22,872 KB
testcase_02 AC 54 ms
20,796 KB
testcase_03 AC 56 ms
22,752 KB
testcase_04 AC 56 ms
20,732 KB
testcase_05 AC 57 ms
20,900 KB
testcase_06 AC 56 ms
20,700 KB
testcase_07 AC 55 ms
22,824 KB
testcase_08 AC 57 ms
20,724 KB
testcase_09 AC 58 ms
20,836 KB
testcase_10 AC 90 ms
20,796 KB
testcase_11 AC 344 ms
21,092 KB
testcase_12 AC 264 ms
20,944 KB
testcase_13 AC 949 ms
23,256 KB
testcase_14 AC 349 ms
21,132 KB
testcase_15 AC 1,139 ms
21,640 KB
testcase_16 AC 1,352 ms
23,620 KB
testcase_17 AC 679 ms
21,224 KB
testcase_18 AC 566 ms
21,256 KB
testcase_19 TLE -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Text;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;

public class Program {
    static int MOD = 1000000007;
    static Dictionary<int, long> memo = new Dictionary<int, long>() { {1, 1} };
    static long f (int n) {
        if (memo.ContainsKey(n)) { return memo[n]; }
        long s = 0;
        for (int i = 1; i < n; ++i) {
            if (n % 2 == 0 && i % 2 == 1) {
                s = (s + f(i)) % MOD;
            } else if (n % 2 == 1 && i % 2 == 0) {
                s = (s + f(i)) % MOD;
            }
        }
        memo.Add(n, (s * n) % MOD);
        return memo[n];
    }
    
    static void Main (string[] args) {
        int N = int.Parse(Console.ReadLine());
        Console.WriteLine(f(N));
    }
}
0