結果

問題 No.2615 ペアの作り方
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-01-26 22:49:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,437 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 171,000 KB
実行使用メモリ 8,420 KB
最終ジャッジ日時 2024-01-26 22:49:44
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// Problem: No.2615 ペアの作り方
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2615
// Memory Limit: 512 MB
// Time Limit: 2000 ms

#include<bits/stdc++.h>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe; 
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=1e6+9,Mod=998244353;
ll n,a[N],b[N],ans=1,c1,c2;
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read();
	rep(i,1,n)a[i]=read();
	rep(i,1,n)b[i]=read();
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	rep(i,1,n){
		if(a[i]<b[n-i+1])c1++;
		else c2++;
	}
	per(i,c1,1){
		ll l=c2+1,r=n,pos=n+1;
		while(l<=r){
			ll mid=(l+r)>>1;
			if(a[i]<=b[mid])pos=mid,r=mid-1;
			else l=mid+1;
		}
		ll cnt=n-pos+1;
		if(c1==i)ans=ans*cnt%Mod;
		else ans=ans*max(0ll,cnt-(c1-i))%Mod;
	}
	rep(i,1,c2){
		ll l=c1+1,r=n,pos=n+1;
		while(l<=r){
			ll mid=(l+r)>>1;
			if(b[i]<=a[mid])pos=mid,r=mid-1;
			else l=mid+1;
		}
		ll cnt=n-pos+1;
		if(c2==i)ans=ans*cnt%Mod;
		else ans=ans*max(0ll,cnt-(c2-i))%Mod;
	}
	write(ans);
	return 0;
}
0