Submission #2443890


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,a;
ll inf = 1e9+7;

int main(){
	cin >> N;
	vector<P> v(2*N);
	for(int i=0;i<2*N;i++){
		if(i<N){
			cin >> a;
			v[i] = P(a,1);
		}else{
			cin >> a;
			v[i] = P(a,-1);
		}
	}
	sort(v.begin(),v.end());
	ll  c = 0;
	ll ans = 1;
	for(int i=0;i<2*N;i++){
		if(c*v[i].second>=0){
			c += v[i].second;
		}else{
			ans = (ans*abs(c))%inf;
			if(c>0) c--;
			else c++;
		}
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task A - 1D Matching
User idsigma
Language C++14 (GCC 5.4.1)
Score 500
Code Size 597 Byte
Status AC
Exec Time 100 ms
Memory 3328 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 59 ms 2176 KB
001.txt AC 22 ms 896 KB
002.txt AC 30 ms 1152 KB
003.txt AC 34 ms 1408 KB
004.txt AC 87 ms 3072 KB
005.txt AC 100 ms 3328 KB
006.txt AC 97 ms 3328 KB
007.txt AC 96 ms 3328 KB
008.txt AC 98 ms 3328 KB
009.txt AC 97 ms 3328 KB
010.txt AC 96 ms 3328 KB
011.txt AC 96 ms 3328 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB