結果

問題 No.2615 ペアの作り方
ユーザー HaaHaa
提出日時 2024-01-26 21:32:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,534 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 177,516 KB
実行使用メモリ 8,676 KB
最終ジャッジ日時 2024-01-26 21:32:15
合計ジャッジ時間 3,531 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 99 ms
6,884 KB
testcase_16 AC 124 ms
6,884 KB
testcase_17 AC 98 ms
6,756 KB
testcase_18 AC 102 ms
8,676 KB
testcase_19 AC 99 ms
6,884 KB
testcase_20 AC 99 ms
6,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

long long inv(int n){
    static vector<long long> a={1,1};
    if((int)a.size()<=n){
        for(int i=a.size();i<=n;i++)
            a.push_back(MOD-a[MOD%i]*(MOD/i)%MOD);
    }
    return a[n];
}
long long fact(int n){
    static vector<long long> a={1,1};
    if((int)a.size()<=n){
        for(int i=a.size();i<=n;i++)
            a.push_back(a.back()*i%MOD);
    }
    return a[n];
}
long long finv(int n){
    static vector<long long> a={1,1};
    if((int)a.size()<=n){
        for(int i=a.size();i<=n;i++)
            a.push_back(a.back()*inv(i)%MOD);
    }
    return a[n];
}
long long com(int n, int k){
    if(n<k||n<0||k<0) return 0;
    return fact(n)*finv(k)%MOD*finv(n-k)%MOD;
}

int main(){
    int n; cin >> n;
    VI x(n), y(n);
    REP(i,n) cin >> x[i];
    REP(i,n) cin >> y[i];
    sort(ALL(x));
    sort(ALL(y),greater<ll>());
    y.push_back(-1);
    int a=0, b=0;
    for(int i=n-1;i>=0;i--){
        if(x[i]>y[i])
            a++;
        if(y[i]!=y[i+1]&&x[i]<=y[i])
            break;
        b++;
    }
    cout << com(b,a)*fact(a)%MOD*fact(n-a)%MOD << endl;
    return 0;
}
0