Submission #2702367


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  vector<int> b(N);
  rep(i, 0, N) { cin >> b[i]; }
  vector<pair<int, int>> v;
  rep(i, 0, N) { v.push_back(make_pair(a[i], 0)); }
  rep(i, 0, N) { v.push_back(make_pair(b[i], 1)); }
  sort(all(v));
  dump(v);

  int cnta = 0, cntb = 0, ans = 1;
  rep(i, 0, 2*N) {
    if (v[i].second == 0) {
      if (cntb > 0) {
        (ans *= cntb) %= MOD;
        cntb--;
      } else
        cnta++;
    } else {
      if (cnta > 0) {
        (ans *= cnta) %= MOD;
        cnta--;
      } else
        cntb++;
    }
    dump(ans,cnta,cntb);
  }
  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User norma
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1602 Byte
Status AC
Exec Time 41 ms
Memory 8048 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 24 ms 3444 KB
001.txt AC 9 ms 1784 KB
002.txt AC 13 ms 1912 KB
003.txt AC 14 ms 2932 KB
004.txt AC 36 ms 6000 KB
005.txt AC 40 ms 6256 KB
006.txt AC 40 ms 7024 KB
007.txt AC 40 ms 7280 KB
008.txt AC 40 ms 8048 KB
009.txt AC 40 ms 7536 KB
010.txt AC 41 ms 7280 KB
011.txt AC 40 ms 6768 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB