結果

問題 No.554 recurrence formula
ユーザー legosukelegosuke
提出日時 2017-12-01 00:56:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 471 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 147,624 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-08-18 11:14:14
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

int main(void) {
  int n;
  cin >> n;

  vector<ll> a, cum[2];
  a.push_back(1);
  cum[1].push_back(1);
  for (int i = 2; i <= n; i++) {
    ll aa = i * cum[(i + 1) & 1].back() % mod;
    a.push_back(aa);
    cum[i & 1].push_back(aa);
    if (cum[i & 1].size() > 1) {
      cum[i & 1].back() += cum[i & 1][(i - 1) / 2 - 1];
    }
  }
  cout << a[n - 1] << endl;

  return 0;
}
0