Submission #3729379


Source Code Expand

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<P> p;
	REP(i, n) {
		ll a;
		cin >> a;
		p.pb(P(a, 0));
	}
	REP(i, n) {
		ll b;
		cin >> b;
		p.pb(P(b, 1));
	}
	sort(ALL(p));
	ll ca = 0, cb = 0;
	ll ans = 1;
	REP(i, 2 * n) {
		if(p[i].second == 0) {
			if(cb == 0) ca++;
			else {
				ans *= cb; ans %= MOD;
				cb--;
			}
		} else {
			if(ca == 0) cb++;
			else {
				ans *= ca; ans %= MOD;
				ca--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */

Submission Info

Submission Time
Task A - 1D Matching
User gazelle
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1328 Byte
Status AC
Exec Time 41 ms
Memory 6384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 14
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 24 ms 2420 KB
001.txt AC 9 ms 1400 KB
002.txt AC 12 ms 1400 KB
003.txt AC 15 ms 2420 KB
004.txt AC 35 ms 4720 KB
005.txt AC 40 ms 6384 KB
006.txt AC 40 ms 5744 KB
007.txt AC 39 ms 6384 KB
008.txt AC 39 ms 4592 KB
009.txt AC 41 ms 5360 KB
010.txt AC 39 ms 6000 KB
011.txt AC 39 ms 5744 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB