結果

問題 No.824 Many Shifts Hard
ユーザー gazellegazelle
提出日時 2019-04-26 22:56:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 124,336 KB
実行使用メモリ 233,600 KB
最終ジャッジ日時 2024-05-04 00:20:48
合計ジャッジ時間 5,946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 17 ms
13,312 KB
testcase_03 AC 105 ms
67,200 KB
testcase_04 AC 87 ms
38,656 KB
testcase_05 AC 317 ms
176,512 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 66 ms
17,792 KB
testcase_08 AC 251 ms
158,592 KB
testcase_09 AC 226 ms
100,352 KB
testcase_10 AC 19 ms
6,528 KB
testcase_11 AC 52 ms
15,232 KB
testcase_12 AC 116 ms
56,448 KB
testcase_13 AC 188 ms
138,880 KB
testcase_14 AC 315 ms
233,600 KB
testcase_15 AC 274 ms
205,056 KB
testcase_16 AC 20 ms
15,872 KB
testcase_17 AC 306 ms
230,656 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 448 ms
233,600 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 451 ms
233,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n, k;
	cin >> n >> k;
	if(n == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<vector<vector<lint>>> dp(k + 1, vector<vector<lint>>(k + 10, vector<lint>(k + 10, 0)));
	REP(i, k + 1) REP(j, k + 10) REP(l, k + 10) {
		if(j >= l) continue;
		if(i == 0) {
			if(j == 0 && l == 1) dp[i][j][l] = 1;
		} else {
			if(j == 0) {
				dp[i][j][l] = (n - 1) * dp[i - 1][j][l]; dp[i][j][l] %= MOD;
				if(l > 1) dp[i][j][l] += dp[i - 1][j][l - 1]; dp[i][j][l] %= MOD;
			} else {
				dp[i][j][l] = (n - 2) * dp[i - 1][j][l]; dp[i][j][l] %= MOD;
				if(l - j > 1) {
					dp[i][j][l] += dp[i - 1][j][l - 1]; dp[i][j][l] %= MOD;
				}
				if(j) {
					dp[i][j][l] += dp[i - 1][j - 1][l]; dp[i][j][l] %= MOD;
				} else {
					dp[i][j][l] += dp[i - 1][j][l]; dp[i][j][l] %= MOD;
				}
			}
		}
	}
	lint ans = 0;
	FOR(i, 1, n + 1) {
		for(lint j = 0; j <= k; j++) {
			if(i + j <= n) {
				ans += i * dp[k][1 + j - 1][1 + j];
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
/* --------------------------------------- */
0