結果

問題 No.336 門松列列
ユーザー mayoko_mayoko_
提出日時 2016-01-16 10:35:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 693 ms
コンパイル使用メモリ 80,168 KB
実行使用メモリ 34,048 KB
最終ジャッジ日時 2023-09-02 18:44:53
合計ジャッジ時間 1,585 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
33,864 KB
testcase_01 AC 13 ms
33,840 KB
testcase_02 AC 12 ms
33,864 KB
testcase_03 AC 12 ms
33,756 KB
testcase_04 AC 23 ms
33,864 KB
testcase_05 AC 12 ms
33,772 KB
testcase_06 AC 14 ms
33,800 KB
testcase_07 AC 16 ms
33,832 KB
testcase_08 AC 18 ms
33,844 KB
testcase_09 AC 22 ms
33,860 KB
testcase_10 AC 22 ms
33,932 KB
testcase_11 AC 22 ms
34,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const ll MOD = 1e9+7;

ll dp[1010][2];
ll C[2020][2020];
int M;
vector<int> length;

ll dfs(int cur, int f) {
    if (cur == M) return f==0 ? 1 : -1;
    ll& ret = dp[cur][f];
    if (ret >= 0) return ret;
    ret = 0;
    int sum = 0;
    for (int i = cur; i < M; i++) {
        sum += length[i];
        ll tmp = C[2*cur+sum][2*cur];
        int nf = f^((i-cur)&1);
        (tmp *= dfs(i+1, nf)) %= MOD;
        (tmp += MOD) %= MOD;
        ret += tmp;
    }
    ret %= MOD;
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    for (int i = 0; i < 2020; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) C[i][j] = (C[i-1][j-1]+C[i-1][j]) % MOD;
    }
    cin >> N;
    if (N <= 2) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < N; i+=2) length.push_back(min(2, N-i));
    M = length.size();
    memset(dp, -1, sizeof(dp));
    ll ans = dfs(0, 0);
    (ans *= 2) %= MOD;
    cout << ans << endl;
    return 0;
}
0