結果
| 問題 | No.1001 注文の多い順列 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-10-08 18:15:44 |
| 言語 | C++11 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
不安定
|
| 実行時間 | 50 ms / 2,000 ms |
| + 434µs | |
| コード長 | 1,041 bytes |
| 記録 | |
| コンパイル時間 | 919 ms |
| コンパイル使用メモリ | 179,784 KB |
| 実行使用メモリ | 49,920 KB |
| 最終ジャッジ日時 | 2026-10-08 18:15:49 |
| 合計ジャッジ時間 | 3,762 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#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]);
}
vjudge1