Submission #15565584


Source Code Expand

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

using P = pair<int, int>;
int n;
vector<P> v;

ModInt<> solve();

int main() {
  cin >> n;
  for (int t = 0; t < 2; ++t)
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      v.emplace_back(x, t);
    }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res = 1;
  int cnt[2] = {};
  for (auto p : v) {
    if (!cnt[!p.second])
      ++cnt[p.second];
    else
      res *= cnt[!p.second]--;
  }
  return res;
}

Submission Info

Submission Time
Task A - 1D Matching
User m_tsubasa
Language C++ (GCC 9.2.1)
Score 500
Code Size 2570 Byte
Status
Exec Time 84 ms
Memory 5328 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0.txt, example1.txt
All 500 / 500 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 56 ms 4064 KB
001.txt 28 ms 3672 KB
002.txt 30 ms 3792 KB
003.txt 36 ms 4240 KB
004.txt 78 ms 5260 KB
005.txt 81 ms 5288 KB
006.txt 81 ms 5168 KB
007.txt 82 ms 5328 KB
008.txt 83 ms 5252 KB
009.txt 82 ms 5288 KB
010.txt 79 ms 5256 KB
011.txt 84 ms 5168 KB
example0.txt 6 ms 3440 KB
example1.txt 2 ms 3612 KB