Submission #3237251


Source Code Expand

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

constexpr int mod = 1e9+7;

int main(){
  int n; cin >> n;
  int a[n], b[n];
  pair<int, int> c[2*n];
  REP(i, n){
    cin >> a[i];
    c[i] = {a[i], 0};
  }
  REP(i, n){
    cin >> b[i];
    c[i+n] = {b[i], 1};
  }

  sort(c, c+2*n);

  ll ans = 1, com = 0, ele = 0;
  REP(i, 2*n){
    if(c[i].second == 0){
      if(ele >= 1){
        (ans *= ele) %= mod;
        ele--;
      }
      else{
        com++;
      }
    }
    else{
      if(com >= 1){
        (ans *= com) %= mod;
        com--;
      }
      else{
        ele++;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User kobajin
Language C++14 (GCC 5.4.1)
Score 500
Code Size 857 Byte
Status AC
Exec Time 123 ms
Memory 2560 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 73 ms 1664 KB
001.txt AC 27 ms 768 KB
002.txt AC 37 ms 896 KB
003.txt AC 41 ms 1024 KB
004.txt AC 107 ms 2304 KB
005.txt AC 123 ms 2560 KB
006.txt AC 121 ms 2560 KB
007.txt AC 122 ms 2560 KB
008.txt AC 121 ms 2560 KB
009.txt AC 122 ms 2560 KB
010.txt AC 121 ms 2560 KB
011.txt AC 122 ms 2560 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB