結果

問題 No.554 recurrence formula
ユーザー nksk38nksk38
提出日時 2017-08-11 23:12:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 907 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 79,568 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-20 23:28:08
合計ジャッジ時間 5,500 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 75 ms
6,940 KB
testcase_12 AC 55 ms
6,940 KB
testcase_13 AC 231 ms
6,944 KB
testcase_14 AC 74 ms
6,940 KB
testcase_15 AC 276 ms
6,940 KB
testcase_16 AC 336 ms
6,944 KB
testcase_17 AC 159 ms
6,948 KB
testcase_18 AC 129 ms
6,944 KB
testcase_19 TLE -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

ll mod = ll(1e9 + 7);
ll memo[100010];
int n; 

int dfs(int x, int m) {
	ll sum = 0;
	if (x == 1)return 1;
	if (memo[x])return memo[x];
	if (x % 2 == 0) {
		for (int i = 1; i <= m- 1; i += 2){
			sum += dfs(i,i);
			sum %= mod;
		}
		return memo[m] = (sum * m) % mod;
	}
	else {
		for (int i = 2; i <= m - 1; i += 2) {
			sum += dfs(i,i);
			sum %= mod;
		}
		return memo[m] = (sum * m) % mod;
	}
}

int main()
{
	cin >> n;
	cout << dfs(n,n) << endl;
	return 0;
}
0