結果

問題 No.1001 注文の多い順列
コンテスト
ユーザー vjudge1
提出日時 2026-10-16 12:08:59
言語 C++23(gnu拡張gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 35 ms / 2,000 ms
+ 392µs
コード長 1,039 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,457 ms
コンパイル使用メモリ 353,988 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2026-10-16 12:09:20
合計ジャッジ時間 7,449 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/*
Problem: Yukicoder No.1001 ???????
Time Limit: 2000 ms
Memory Limit: 512 MB
*/

#include <bits/stdc++.h>
#define nmf(i, s, e) for (int i = s; i <= e; i++)
#define ref(i, s, e) for (int i = s; i >= e; i--)
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
int cnt[3003][2];
int n;
const LL mod = 1e9 + 7;
LL f[3003][3003];
void solve()
{
    cin >> n;
    nmf(i, 1, n)
    {
        int t, x;
        cin >> t >> x;
        cnt[x][t]++;
    }
    nmf(i, 1, n) cnt[i][0] += cnt[i - 1][0];
    nmf(i, 1, n) cnt[i][1] += cnt[i - 1][1];
    f[0][0] = 1;
    nmf(a, 0, cnt[n][1])
    {
        nmf(b, 0, cnt[n][0])
        {
            int i = a + b + 1;
            if (i > n)
                continue;
            f[a + 1][b] = (f[a + 1][b] + f[a][b] * (cnt[i][1] - a)) % mod;
            f[a][b + 1] = (f[a][b + 1] + f[a][b] * (b + 1 - cnt[i - 1][0])) % mod;
        }
    }
    cout << f[cnt[n][1]][cnt[n][0]] << endl;
    return;
}
signed main()
{
    int T = 1;
    while (T--)
        solve();
    return 0;
}
0