Submission #1678169


Source Code Expand

//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, a[100005], b[100005];
const lint MOD = (lint)1e9 + 7;
lint fact[100005];

int main() {
	cin >> N;
	for_(i,0,N) cin >> a[i];
	for_(i,0,N) cin >> b[i];
	sort(a, a+N);
	sort(b, b+N);
	
	fact[1] = 1;
	for_(i,2,N+1) fact[i] = (fact[i-1] * i) % MOD;
	
	Vec< int > vL;
	int len = 0;
	bool dir = false;
	for_(i,0,N) {
		if (len == 0) {
			dir = (a[i] < b[i]);
			len = 1;
		} else {
			if (dir) {
				if (a[i] < b[i]) {
					++len;
				} else {
					vL.push_back(len);
					len = 0;
					--i;
				}
			} else {
				if (a[i] > b[i]) {
					++len;
				} else {
					vL.push_back(len);
					len = 0;
					--i;
				}				
			}
		}
	}
	vL.push_back(len);
		
	lint ans = 1;
	for (int x : vL) ans = (ans * fact[x]) % MOD;
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Submission Info

Submission Time
Task A - 1D Matching
User tsukasa_diary
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2187 Byte
Status WA
Exec Time 93 ms
Memory 2176 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 3
WA × 11
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 57 ms 1152 KB
001.txt WA 21 ms 640 KB
002.txt WA 29 ms 768 KB
003.txt WA 32 ms 768 KB
004.txt WA 83 ms 1664 KB
005.txt WA 92 ms 1792 KB
006.txt WA 92 ms 1792 KB
007.txt WA 92 ms 1792 KB
008.txt WA 92 ms 1792 KB
009.txt WA 92 ms 1792 KB
010.txt AC 92 ms 1792 KB
011.txt WA 93 ms 2176 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB