Submission #1837575


Source Code Expand

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int M = 1000000007;

int main(){
	int n;
	cin >> n;

	vector<pair<int, bool>> p(n * 2); //1 : PC, 0 : power supply
	rep(i,n){
		int a;
		cin >> a;
		p[i] = make_pair(a, true);
	}
	rep(i,n){
		int b;
		cin >> b;
		p[i + n] = make_pair(b, false);
	}

	sort(all(p));

	int pc = 0, power = 0;
	long long ans = 1;
	for(auto i : p){
		if(i.second){
			if(power != 0){
				ans *= power;
				power--;
			}else{
				pc++;
			}
		}else{
			if(pc != 0){
				ans *= pc;
				pc--;
			}else{
				power++;
			}
		}
		ans %= M;
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task A - 1D Matching
User noy72
Language C++14 (GCC 5.4.1)
Score 500
Code Size 853 Byte
Status AC
Exec Time 95 ms
Memory 1792 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 58 ms 1152 KB
001.txt AC 21 ms 640 KB
002.txt AC 30 ms 768 KB
003.txt AC 33 ms 768 KB
004.txt AC 85 ms 1664 KB
005.txt AC 95 ms 1792 KB
006.txt AC 95 ms 1792 KB
007.txt AC 95 ms 1792 KB
008.txt AC 95 ms 1792 KB
009.txt AC 95 ms 1792 KB
010.txt AC 95 ms 1792 KB
011.txt AC 95 ms 1792 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB