結果

問題 No.824 Many Shifts Hard
ユーザー gazellegazelle
提出日時 2019-04-26 22:56:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 1,791 bytes
コンパイル時間 1,373 ms
コンパイル使用メモリ 122,592 KB
実行使用メモリ 233,572 KB
最終ジャッジ日時 2023-08-16 16:19:49
合計ジャッジ時間 5,755 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 16 ms
13,272 KB
testcase_03 AC 99 ms
67,228 KB
testcase_04 AC 83 ms
38,640 KB
testcase_05 AC 304 ms
176,164 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 65 ms
17,676 KB
testcase_08 AC 233 ms
158,480 KB
testcase_09 AC 215 ms
100,312 KB
testcase_10 AC 18 ms
6,596 KB
testcase_11 AC 52 ms
15,288 KB
testcase_12 AC 112 ms
56,500 KB
testcase_13 AC 172 ms
138,812 KB
testcase_14 AC 290 ms
233,464 KB
testcase_15 AC 254 ms
205,012 KB
testcase_16 AC 18 ms
15,884 KB
testcase_17 AC 287 ms
230,744 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 427 ms
233,464 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 429 ms
233,572 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