Submission #3514217


Source Code Expand

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 1; i <= (n); i ++) 
using namespace std;

inline void fastio(void) {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
template <typename T>
inline void read(T &x) {
  cin >> x;
}

namespace {
  const int mo = 1e9 + 7;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
  inline int pw(int a, int k) {
    int ans = 1;
    for (; k; k >>= 1, a = mul(a, a))
      if (k & 1) ans = mul(ans, a);
    return ans;
  }
}
const int N = 3e5 + 233;
int n, m, x;
pair <int, int> a[N];

signed main(void) {
  fastio();
  cin >> n;
  rep (i, n) cin >> x, a[++ m] = {x, 0};
  rep (i, n) cin >> x, a[++ m] = {x, 1};
  sort(a + 1, a + m + 1);
  int x = 0, y = 0, ans = 1;
  for (int i = 1; i <= m; i ++) {
    if (a[i].second == 0) {
      if (y) ans *= y --;
      else x ++;
    } else {
      if (x) ans *= x --;
      else y ++;
    }
    ans %= mo;
  }
  cout << ans << "\n";
}

Submission Info

Submission Time
Task A - 1D Matching
User foreverpiano
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1186 Byte
Status AC
Exec Time 37 ms
Memory 4352 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 23 ms 2176 KB
001.txt AC 9 ms 896 KB
002.txt AC 12 ms 1280 KB
003.txt AC 13 ms 1280 KB
004.txt AC 33 ms 4352 KB
005.txt AC 37 ms 4352 KB
006.txt AC 37 ms 4352 KB
007.txt AC 37 ms 4352 KB
008.txt AC 37 ms 4352 KB
009.txt AC 37 ms 4352 KB
010.txt AC 37 ms 4352 KB
011.txt AC 37 ms 4352 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB