結果

問題 No.1001 注文の多い順列
ユーザー tempura_pptempura_pp
提出日時 2020-02-18 02:14:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 73,052 KB
実行使用メモリ 49,920 KB
最終ジャッジ日時 2024-04-16 04:03:03
合計ジャッジ時間 2,683 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 56 ms
43,392 KB
testcase_19 AC 51 ms
39,936 KB
testcase_20 AC 32 ms
28,544 KB
testcase_21 AC 36 ms
26,368 KB
testcase_22 AC 75 ms
49,792 KB
testcase_23 AC 68 ms
49,664 KB
testcase_24 AC 68 ms
49,408 KB
testcase_25 AC 64 ms
48,768 KB
testcase_26 AC 78 ms
48,000 KB
testcase_27 AC 79 ms
48,896 KB
testcase_28 AC 74 ms
49,024 KB
testcase_29 AC 55 ms
49,408 KB
testcase_30 AC 55 ms
47,744 KB
testcase_31 AC 58 ms
49,408 KB
testcase_32 AC 52 ms
49,920 KB
testcase_33 AC 82 ms
49,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>

using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const ll mod=1e9+7 ;

ll dp[3030][3030];
int main(){
    int n;
    cin>>n;
    pair<int,int> p[n];
    int cnt = 0;
    rep(i,n){
        cin>>p[i].second>>p[i].first;
        if(p[i].second==1){
            --p[i].first;++cnt;
        }
    }
    sort(p,p+n);
    dp[0][0]=1;
    rep(i,n)rep(j,i+1){
        dp[i][j]%=mod;
        int used = i-j;
        if(p[i].second==0)dp[i+1][j]+=dp[i][j]*max(p[i].first-used,0)%mod;
        if(p[i].second==1){
            dp[i+1][j]+=dp[i][j]*max(p[i].first-used,0)%mod;
            dp[i+1][j+1]+=dp[i][j];
        }
    }
    ll fact = 1;
    rep(j,n+1){
        dp[n][j]=dp[n][j]*fact%mod;
        fact =fact*(j+1)%mod;
    }
    ll ans = 0;
    rep(i,cnt+1){
        if(i%2==0)ans += dp[n][cnt-i];
        else ans += mod-dp[n][cnt-i];
    }
    cout<<ans%mod<<endl;
    return 0;
}
0