結果

問題 No.535 自然数の収納方法
ユーザー square1001square1001
提出日時 2018-04-17 20:34:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 67,784 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 11:08:04
合計ジャッジ時間 2,012 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 16 ms
4,380 KB
testcase_09 AC 20 ms
4,376 KB
testcase_10 AC 24 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 25 ms
4,376 KB
testcase_16 AC 16 ms
4,380 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 27 ms
4,380 KB
testcase_20 AC 28 ms
4,376 KB
testcase_21 AC 28 ms
4,376 KB
testcase_22 AC 27 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int n, dp[4009], ndp[4009], mod = 1000000007;
void calc() {
	for (int i = 0; i < n - 1; i++) {
		int x = (i > 0 ? i : 1);
		for (int j = 0; j < x; j++) {
			ndp[0] += dp[j];
			if (ndp[0] >= mod) ndp[0] -= mod;
		}
		for (int j = 1; j < n; j++) {
			ndp[j] = ndp[j - 1] + dp[j + x - 1];
			if (ndp[j] >= mod) ndp[j] -= mod;
		}
		for (int j = 0; j < n; j++) dp[j] = ndp[j], ndp[j] = 0;
	}
}
int main() {
	cin >> n;
	fill(dp, dp + n, 1);
	calc();
	int ret = 0;
	for (int i = 0; i < n; i++) ret = (ret + dp[i]) % mod;
	fill(dp, dp + n, 0); dp[0] = 1;
	calc();
	cout << (ret - dp[n - 1] + mod) % mod << endl;
	return 0;
}
0