結果

問題 No.1001 注文の多い順列
コンテスト
ユーザー vjudge1
提出日時 2026-10-04 16:03:21
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 32 ms / 2,000 ms
+ 386µs
コード長 744 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,688 ms
コンパイル使用メモリ 357,888 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2026-10-04 16:03:32
合計ジャッジ時間 5,005 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll n,t,x,dp[3005][3005],cnt;
vector<int> V[2];
int main(){ cin >> n,dp[0][0]=1;
    for(int i=1;i<=n;i++) cin >> t >> x,V[t].push_back(x-1),cnt+=(t==0);
    sort(V[0].begin(),V[0].end()),sort(V[1].begin(),V[1].end());
    for(int i=0;i<n;i++){
        int cnt0=0,cnt1=0;
        for(int x:V[0]) cnt0+=(i<=x);
        for(int x:V[1]) cnt1+=(x<=i);
        for(int x=0;x<=cnt;x++) 
            if(0<=i-x && i-x<=n-cnt && dp[x][i-x]){
                if(i-x<n-cnt) (dp[x][i-x+1]+=dp[x][i-x]*max(cnt1-(i-x),0))%=mod;
                if(x<cnt) (dp[x+1][i-x]+=dp[x][i-x]*max(cnt0-(cnt-x-1),0ll))%=mod;
            }
    } cout << dp[cnt][n-cnt]; 
    return 0;
}
0