Submission #3419183


Source Code Expand

#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 222222


ll fac[MAX];

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);


  fac[1] = 1;
  FOR(i, 2, MAX) (fac[i] = fac[i - 1] * i) %= mod;
  cin >> n;
  vpll v;
  pll p;
  rep(i, n) {
	cin >> p.first;
	p.second = 0;
	v.pb(p);
  }
  rep(i, n) {
	cin >> p.first;
	p.second = 1;
	v.pb(p);
  }
  sort(all(v));
  ans = 1;
  ll acnt = 0, bcnt = 0;
  rep(i, 2 * n) {
	if (v[i].second == 0) {
	  acnt++;
	  if (bcnt && acnt >= bcnt) {
		(ans *= fac[bcnt]) %= mod;
		acnt -= bcnt;
		bcnt = 0;
	  }
	}
	else {
	  bcnt++;
	  if (acnt && bcnt >= acnt) {
		(ans *= fac[acnt]) %= mod;
		bcnt -= acnt;
		acnt = 0;
	  }
	}
	//cout << acnt << " " << bcnt << " " << ans << endl;
  }
  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User hide1214
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2004 Byte
Status WA
Exec Time 41 ms
Memory 8176 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 25 ms 4212 KB
001.txt WA 11 ms 3192 KB
002.txt WA 14 ms 3192 KB
003.txt WA 16 ms 4212 KB
004.txt WA 36 ms 6768 KB
005.txt WA 41 ms 7920 KB
006.txt WA 40 ms 7664 KB
007.txt WA 40 ms 6512 KB
008.txt WA 40 ms 6512 KB
009.txt WA 40 ms 7024 KB
010.txt AC 39 ms 7024 KB
011.txt AC 40 ms 8176 KB
example0.txt AC 3 ms 2048 KB
example1.txt AC 3 ms 2048 KB