結果
| 問題 |
No.1001 注文の多い順列
|
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2020-02-28 22:47:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 1,480 bytes |
| コンパイル時間 | 1,084 ms |
| コンパイル使用メモリ | 104,332 KB |
| 実行使用メモリ | 73,728 KB |
| 最終ジャッジ日時 | 2024-10-13 18:37:50 |
| 合計ジャッジ時間 | 3,245 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
void add(ll &a,ll b){
a=(a+b)%MOD;
}
void mul(ll &a,ll b){
a%=MOD;b%=MOD;
a=a*b%MOD;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
vector<int> U,D;
rep(i,N){
int t,x;cin>>t>>x;
if(t==0) U.push_back(x);
else D.push_back(x);
}
int S=U.size();
int T=D.size();
if(S) sort(U.begin(),U.end());
if(T) sort(D.begin(),D.end());
vector<vector<ll>> dp(N+1,vector<ll>(S+1,0));
dp[0][0]=1;
for(int i=0;i<N;i++){
int val=i+1;
for(int j=0;j<=S;j++){
if(dp[i][j]==0) continue;
int t=i-j;
if(t+1<=T){
if(D[t]<=val){
int z=upper_bound(D.begin(),D.end(),val)-D.begin();
ll res=dp[i][j];
mul(res,z-t);
add(dp[i+1][j],res);
}
}
if(j+1<=S){
if(U[j]>=val){
int z=lower_bound(U.begin(),U.end(),val)-U.begin();
ll res=dp[i][j];
mul(res,j-z+1);
add(dp[i+1][j+1],res);
}
}
}
}
cout<<dp[N][S]<<endl;
return 0;
}
snow39