結果

問題 No.1001 注文の多い順列
ユーザー outlineoutline
提出日時 2020-03-03 01:29:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,745 bytes
コンパイル時間 1,187 ms
コンパイル使用メモリ 112,840 KB
実行使用メモリ 27,136 KB
最終ジャッジ日時 2024-04-21 23:01:05
合計ジャッジ時間 2,827 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 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 52 ms
23,296 KB
testcase_19 AC 45 ms
21,376 KB
testcase_20 AC 30 ms
16,128 KB
testcase_21 AC 27 ms
14,976 KB
testcase_22 AC 61 ms
27,008 KB
testcase_23 AC 59 ms
26,880 KB
testcase_24 AC 60 ms
27,136 KB
testcase_25 AC 59 ms
26,624 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 14 ms
5,888 KB
testcase_28 AC 19 ms
8,448 KB
testcase_29 AC 39 ms
20,480 KB
testcase_30 AC 41 ms
21,376 KB
testcase_31 AC 45 ms
23,296 KB
testcase_32 AC 30 ms
15,488 KB
testcase_33 AC 10 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 参考文献 : http://kmjp.hatenablog.jp/entry/2020/02/29/0930

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const int mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int n;
vector<int> input[2];
ll dp[3050][3050];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        input[x].push_back(--y);
    }

    dp[0][0] = 1;
    int sz0 = input[0].size(), sz1 = input[1].size();
    for(int i = 0; i < n; ++i){
        int cnt0 = 0, cnt1 = 0;
        for(int j : input[0])   cnt0 += j >= i;
        for(int j : input[1])   cnt1 += i >= j;
        for(int j = 0; j <= sz0; ++j){
            int k = i - j;
            if(k < 0 || k > sz1)    continue;
            if(j < sz0)     chadd(dp[j+1][k], dp[j][k] * (cnt0 - (sz0 - j - 1)));
            if(k < sz1)     chadd(dp[j][k+1], dp[j][k] * (cnt1 - k));
        }
    }
    ll res = 0;
    for(int i = 0; i <= n; ++i)     chadd(res, dp[i][n-i]);
    cout << res << endl;
}
0