結果

問題 No.1877 俺自身が線グラフになることだ
ユーザー 👑 colognecologne
提出日時 2022-03-17 16:10:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 515 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 116,456 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-14 08:36:35
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 15 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>
#include <iostream>
#include <optional>
#include <vector>
#include <atcoder/modint>

using namespace std;
using Mint = atcoder::modint1000000007;

int main()
{
	int N;
	cin >> N;
	vector<vector<optional<Mint>>> DP(N + 1, vector<optional<Mint>>(N + 1));
	function<Mint(int, int)> f = [&](int a, int b)
	{
		if (a == 0)
			return Mint(1);
		if (b > a)
			return Mint(0);
		if (DP[a][b])
			return *DP[a][b];
		return *(DP[a][b] = f(a - b, b) + f(a, b + 1));
	};
	cout << f(N, 3).val() << endl;
}
0