結果

問題 No.1001 注文の多い順列
コンテスト
ユーザー vjudge1
提出日時 2026-10-08 18:14:27
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 53 ms / 2,000 ms
+ 221µs
コード長 1,052 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 946 ms
コンパイル使用メモリ 179,584 KB
実行使用メモリ 49,920 KB
最終ジャッジ日時 2026-10-08 18:14:41
合計ジャッジ時間 3,847 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define il inline
#define re register
#define pii pair<int,int>
#define fs first
#define sc second
using namespace std;
il int read()
{
	re int x=0;
	re int ff=1;
	re char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')ff=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*ff;
}
const int N=3006;
const int mod=1e9+7;
int t,n,m,f[N][N],a[N],b[N],g[N];
il void add(re int& x,re int y)
{
	x+=y,(x>=mod?x-=mod:0);
	return;
}
signed main()
{
	t=read();
	for(re int i=1;i<=t;i++){
		re int opt,x;
		opt=read(),x=read();
		if(opt)a[++n]=x;
		else b[++m]=x;
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	for(re int i=t,j=m;i;i--){
		g[i]=g[i+1];
		while(j&&b[j]>=i)g[i]++,j--;
	}f[0][0]=1;re int qwq=0;
	for(re int i=1,j=1;i<=t;i++){
		while(j<=n&&a[j]<=i)qwq++,j++;
		for(re int x=0;x<i;x++){
			re int y=i-x-1;
			add(f[x+1][y],f[x][y]*max(qwq-x,0ll)%mod);
			add(f[x][y+1],f[x][y]*max(g[i]-(m-y-1),0ll)%mod);
		}
	}
	printf("%lld\n",f[n][m]);
	return 0;
}
0