結果
問題 | No.314 ケンケンパ |
ユーザー |
![]() |
提出日時 | 2018-07-07 20:09:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 17 ms / 1,000 ms |
コード長 | 901 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 56,872 KB |
実行使用メモリ | 19,036 KB |
最終ジャッジ日時 | 2024-07-05 05:33:26 |
合計ジャッジ時間 | 1,263 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include<iostream>#define M 1000000007#define MAX_N 1000000using namespace std;typedef long long ll;ll fact_n[MAX_N + 1], fact_inv[MAX_N + 1];ll mod_pow(ll a, ll n) {ll x = 1;while (n > 0) {if (n & 1) x = x * a % M;a = a * a % M;n >>= 1;}return x;}ll combination(int n, int r) {if (n == 0 && r == 0) return 1;else if (n < r || n < 0) return 0;ll com = fact_n[n] * fact_inv[r] % M;return com * fact_inv[n - r] % M;}int main(){int n, j;ll com = 0;cin >> n;fact_n[0] = fact_inv[0] = 1;for (int i = 1;i <= MAX_N;i++) fact_n[i] = fact_n[i - 1] * i % M;fact_inv[MAX_N] = mod_pow(fact_n[MAX_N], M - 2);for (int i = MAX_N - 1;i > 0;i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % M;for (int i = 0;i <= n;i++) {if (n - 2 * i >= 0) {j = (n - 2 * i) / 3;com += combination(i + j, i) % M;}}cout << com % M << endl;return 0;}