結果

問題 No.1001 注文の多い順列
コンテスト
ユーザー vjudge1
提出日時 2026-10-09 12:07:32
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.92.0 + ACL)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 31 ms / 2,000 ms
+ 814µs
コード長 817 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,165 ms
コンパイル使用メモリ 206,620 KB
実行使用メモリ 27,136 KB
最終ジャッジ日時 2026-10-09 12:07:36
合計ジャッジ時間 3,164 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;

const int N = 3e3 + 5, mod = 1e9 + 7;
int n, f[N][N];
int a, b, C[2][N];
vector <int> S[2]; 

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int i, j, t, x;
	cin >> n;
	
	for(i = 1; i <= n; i++)
	{
		cin >> t >> x;
		S[t].pb(x);
	}
	
	a = S[0].size(), b = S[1].size();
	
	for(i = 1; i <= n; i++)
	{
		for(auto p : S[0]) C[0][i] += (int)(i <= p);
		for(auto p : S[1]) C[1][i] += (int)(i >= p);
	}
	
	f[0][0] = 1;
	
	for(i = 0; i <= a; i++)
	{
		for(j = 0; j <= b; j++)
		{
			int tmp = i + j + 1;
			if(i < a) f[i + 1][j] = (f[i + 1][j] + f[i][j] * (C[0][tmp] - (a - (i + 1)))) % mod;
			if(j < b) f[i][j + 1] = (f[i][j + 1] + f[i][j] * (C[1][tmp] - j)) % mod;
		}
	}
	
	cout << f[a][b];
	return 0;
}
0