結果

問題 No.1001 注文の多い順列
ユーザー noisy_noiminnoisy_noimin
提出日時 2020-03-05 01:08:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,881 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 127,528 KB
実行使用メモリ 38,656 KB
最終ジャッジ日時 2024-04-22 01:58:16
合計ジャッジ時間 3,372 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
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 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 49 ms
38,272 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 44 ms
38,528 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<Pii> p(n);
    int min_cnt = 0;
    for(int i=0;i<n;++i) {
        cin >> p[i].second >> p[i].first;
        if(p[i].second == 1) {
            --p[i].first;
        } else {
            ++min_cnt;
        }
    }
    sort(p.begin(), p.end());

    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
    dp[0][0] = 1;
    for(int i=0;i<n;++i) {
        for(int j=0;j<=i;++j) {
            if(p[i].second == 1) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
                dp[i+1][j+1] += (dp[i][j] * max(0, p[i].first-j)) % MOD;
                dp[i+1][j+1] %= MOD;
            } else {
                dp[i+1][j+1] += (dp[i][j] * max(0, p[i].first-j)) % MOD;
                dp[i+1][j+1] %= MOD;
            }
        }
    }

    ll fact[n+1];
    fact[0] = 1;
    for(int i=1;i<=n;++i) fact[i] = (fact[i-1] * i) % MOD;

    ll ans = 0LL;
    for(int i=min_cnt;i<=n;++i) {
        if((i-min_cnt) % 2) {
            ans += MOD - dp[n][i] * fact[n-i] % MOD;
        } else {
            ans += dp[n][i] * fact[n-i] % MOD;
        }
        ans %= MOD;
    }
    
    cout << ans << endl;
}
0