結果

問題 No.1001 注文の多い順列
ユーザー startcppstartcpp
提出日時 2020-02-28 22:33:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,698 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 75,884 KB
実行使用メモリ 49,664 KB
最終ジャッジ日時 2024-04-21 19:40:51
合計ジャッジ時間 4,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 55 ms
28,672 KB
testcase_19 AC 53 ms
27,392 KB
testcase_20 AC 35 ms
19,968 KB
testcase_21 AC 32 ms
19,200 KB
testcase_22 AC 68 ms
33,664 KB
testcase_23 AC 65 ms
32,768 KB
testcase_24 AC 64 ms
32,768 KB
testcase_25 AC 63 ms
32,128 KB
testcase_26 AC 96 ms
48,128 KB
testcase_27 AC 93 ms
47,104 KB
testcase_28 AC 86 ms
45,440 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 140 ms
49,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//お誕生日おめでとうございます!!ACください!!
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;

int mod = 1000000007;
int n;
int t[3000], x[3000];
int rt[3001];			//rt[i] = t[0] + … + t[i - 1]
int dp[3001][3001];		//dp[i][j] = 個数 (t[i] == 0:全部守る. t[i] == 1: j個を選んで違反. それ以外は違反してもしなくてもいい(1通りとして後回し).)
int fact[3001];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> t[i] >> x[i];
	
	P pa[3000];
	rep(i, n) {
		if (t[i] == 0) pa[i] = P(x[i], t[i]);
		else pa[i] = P(x[i] - 1, t[i]);
	}
	sort(pa, pa + n);
	rep(i, n) { t[i] = pa[i].second; x[i] = pa[i].first; }
	rep(i, n) { rt[i + 1] = rt[i] + t[i]; }
	
	//rep(i, n) { cout << t[i] << ", " << x[i] << endl; }
	
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, rt[i] + 1) {
			int tempura = i - (rt[i] - j);
			
			if (t[i] == 0) {
				if (x[i] - tempura > 0) {
					dp[i + 1][j] += dp[i][j] * (x[i] - tempura);
					dp[i + 1][j] %= mod;
				}
			}
			
			else {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= mod;
				
				if (x[i] - tempura > 0) {
					dp[i + 1][j + 1] += dp[i][j] * (x[i] - tempura);
					dp[i + 1][j + 1] %= mod;
				}
			}
		}
	}
	
	/*rep(i, n + 1) {
		rep(j, i + 1) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	fact[0] = 1;
	rep(i, n) { fact[i + 1] = (i + 1) * fact[i] % mod; }
	
	int ans = 0;
	rep(j, n + 1) {
		int res = dp[n][j];
		res *= fact[rt[n] - j];
		res %= mod;
		
		if (j % 2 == 0) { ans += res; }
		else { ans += mod - res; }
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}
0