Submission #2606635


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

#define MOD 1000000007

long long N;
long long A[100005];
long long B[100005];
long long memo[100005];

long long cal(long long num){
	if(memo[num] != 0)
		return memo[num];

	if(num == 1)
		return 1;
	
	memo[num] = (num * cal(num-1)) % MOD;
	return memo[num];
}

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
	}
	for(long long i = 0; i < N; i++){
		cin >> B[i];
	}
	sort(A, A + N);
	sort(B, B + N);

	long long ans = 1;
	long long count = 1;

	bool abig = false;
	long long th = B[0];
	if(A[0] > B[0]) {
		abig = true;
		th = A[0];
	}

	for(long long i = 1; i < N; i++){
		if(abig){
			if(A[i] > B[i]){
				if(th < B[i]){
					ans *= cal(count);
					ans %= MOD;
					count = 1;
					th = A[i];
				}else {
					count++;
				}
			}else{
				//A[i] < B[i]
				abig = false;
				ans *= cal(count);
				ans %= MOD;
				count = 1;
				th = B[i];
			}
		}else{
			if(A[i] > B[i]){
				abig = true;
				ans *= cal(count);
				ans %= MOD;
				count = 1;
				th = A[i];
			}else{
				//A[i] < B[i]
				if(th < A[i]){
					ans *= cal(count);
					ans %= MOD;
					count = 1;
					th = B[i];
				}else {
					count++;
				}
			}
		}
	}
	ans *= cal(count);
	ans %= MOD;
	cout << ans << endl;
}

Submission Info

Submission Time
Task A - 1D Matching
User motomuman
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1342 Byte
Status WA
Exec Time 106 ms
Memory 4096 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 4
WA × 10
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 WA 55 ms 1152 KB
001.txt WA 20 ms 640 KB
002.txt WA 28 ms 768 KB
003.txt WA 32 ms 768 KB
004.txt WA 81 ms 1664 KB
005.txt WA 91 ms 1792 KB
006.txt WA 91 ms 1792 KB
007.txt WA 91 ms 1792 KB
008.txt WA 106 ms 1792 KB
009.txt WA 91 ms 1792 KB
010.txt AC 92 ms 4096 KB
011.txt AC 91 ms 1792 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB