Submission #1908481


Source Code Expand

#include <cmath>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100009], b[100009], p[200009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < 2 * n; i++) p[i] = i;
	sort(p, p + 2 * n, [](int v1, int v2) { return (v1 < n ? a[v1] : b[v1 - n]) < (v2 < n ? a[v2] : b[v2 - n]); });
	int d = 0, ret = 1;
	for (int i = 0; i < 2 * n; i++) {
		int nd = d + (p[i] < n ? 1 : -1);
		if (abs(d) > abs(nd)) ret = 1LL * ret * abs(d) % 1000000007;
		d = nd;
	}
	cout << ret << endl;
	return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User square1001
Language C++14 (GCC 5.4.1)
Score 500
Code Size 622 Byte
Status AC
Exec Time 144 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 85 ms 1152 KB
001.txt AC 31 ms 640 KB
002.txt AC 43 ms 768 KB
003.txt AC 48 ms 768 KB
004.txt AC 128 ms 1664 KB
005.txt AC 143 ms 1792 KB
006.txt AC 144 ms 1792 KB
007.txt AC 141 ms 1792 KB
008.txt AC 144 ms 1792 KB
009.txt AC 142 ms 1792 KB
010.txt AC 129 ms 1792 KB
011.txt AC 141 ms 1792 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB