結果
問題 | No.2615 ペアの作り方 |
ユーザー |
![]() |
提出日時 | 2024-01-26 21:32:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,534 bytes |
コンパイル時間 | 1,639 ms |
コンパイル使用メモリ | 178,016 KB |
実行使用メモリ | 8,428 KB |
最終ジャッジ日時 | 2024-09-28 07:43:15 |
合計ジャッジ時間 | 3,059 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#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;}