結果

問題 No.93 ペガサス
ユーザー pekempeypekempey
提出日時 2015-11-10 21:58:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 148 ms / 5,000 ms
コード長 1,299 bytes
コンパイル時間 1,142 ms
コンパイル使用メモリ 145,184 KB
実行使用メモリ 34,852 KB
最終ジャッジ日時 2023-10-11 15:34:15
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 26 ms
9,644 KB
testcase_05 AC 10 ms
5,988 KB
testcase_06 AC 8 ms
5,216 KB
testcase_07 AC 85 ms
23,464 KB
testcase_08 AC 42 ms
13,316 KB
testcase_09 AC 145 ms
34,468 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 6 ms
4,552 KB
testcase_12 AC 124 ms
31,676 KB
testcase_13 AC 37 ms
12,156 KB
testcase_14 AC 15 ms
7,140 KB
testcase_15 AC 110 ms
29,220 KB
testcase_16 AC 19 ms
8,012 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 148 ms
34,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;
ll dp[1010][1010][2][2]; // pos, bad, (n-3, n-1), (n-2, n)

int main() {
	int n;
	cin >> n;
	dp[0][0][0][0] = 1;
	rep (i, n) rep (j, n + 1) rep (k, 2) rep (l, 2) {
		ll v = dp[i][j][k][l];
		int way = i + 1;
		if (k) {
			// n-3,(n+1),n-1
			(dp[i + 1][j][l][true] += v) %= mod;
			// (n+1),n-1,n-3
			(dp[i + 1][j + k][l][true] += v) %= mod;
			way -= 2;
		} else {
			if (i >= 2) {
				// (n+1),n-1 or n-1,(n+1)
				(dp[i + 1][j + k][l][true] += v * 2) %= mod;
				way -= 2;
			}
		}

		// n-2, (n+1), n
		if (l) {
			(dp[i + 1][j + k][false][false] += v) %= mod;
			way -= 1;
		}

		(dp[i + 1][j - 1 + k][l][false] += v * j % mod) %= mod;
		way -= j;
		(dp[i + 1][j + k][l][false] += v * way % mod) %= mod;
	}
	cout << dp[n][0][0][0] << endl;
}
0