結果

問題 No.1001 注文の多い順列
ユーザー kyort0nkyort0n
提出日時 2020-02-28 21:53:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,915 bytes
コンパイル時間 1,735 ms
コンパイル使用メモリ 169,064 KB
実行使用メモリ 73,776 KB
最終ジャッジ日時 2023-08-03 20:06:54
合計ジャッジ時間 5,566 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,452 KB
testcase_15 AC 4 ms
5,300 KB
testcase_16 AC 3 ms
4,716 KB
testcase_17 AC 3 ms
4,516 KB
testcase_18 AC 167 ms
67,348 KB
testcase_19 AC 151 ms
64,092 KB
testcase_20 AC 98 ms
45,264 KB
testcase_21 AC 89 ms
41,396 KB
testcase_22 AC 198 ms
73,744 KB
testcase_23 AC 196 ms
73,596 KB
testcase_24 AC 195 ms
73,404 KB
testcase_25 AC 191 ms
72,660 KB
testcase_26 AC 126 ms
72,096 KB
testcase_27 AC 127 ms
72,848 KB
testcase_28 AC 127 ms
73,072 KB
testcase_29 AC 135 ms
73,316 KB
testcase_30 AC 129 ms
71,756 KB
testcase_31 AC 134 ms
73,540 KB
testcase_32 AC 133 ms
73,776 KB
testcase_33 AC 130 ms
73,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll N;
vector<ll> t, X;
ll dp[3002][3002];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    t.resize(N);
    X.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> t[i] >> X[i];
        X[i]--;
    }
    dp[0][0] = 1;
    ll Up = 0;
    ll Down = 0;
    for(ll val = 0; val < N; val++) {
        for(int i = 0; i < N; i++) {
            if(t[i] == 1 and X[i] == val) Up++;
        }
        for(int before = 0; before <= N; before++) {
            ll delta = Up - before;
            chmax(delta, 0LL);
            dp[val+1][before+1] += dp[val][before] * delta;
            dp[val+1][before+1] %= mod;
            dp[val+1][before] += dp[val][before];
            dp[val+1][before] %= mod;
        }
        for(int i = 0; i < N; i++) {
            if(t[i] == 0 and X[i] == val) {
                for(ll before = 0; before <= N; before++) {
                    ll delta = val + 1 - before - Down;
                    if(delta <= 0) dp[val+1][before] = 0;
                    else dp[val+1][before] *= delta;
                    dp[val+1][before] %= mod;
                }
                Down++;
            }
        }
    }
    ll ans = dp[N][Up];
    /*
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N; j++) {
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }
    */
    cout << ans << endl;
    return 0;
}
0