Submission #2625941


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

ll N;
ll ans = 1;
ll mod = (ll)1e9+7;

void solve() {
    cin >> N;
    vector<pii> obj;
    rep(i,N) {
        int a;
        cin >> a;
        obj.push_back(pii(a, 0));
    }
    rep(i,N) {
        int a;
        cin >> a;
        obj.push_back(pii(a, 1));
    }
    sort(obj.begin(), obj.end());
    multiset<int> st1, st2;
    rep(i,2*N) {
        if (obj[i].second == 0) {
            if (st2.empty()) {
                st1.insert(obj[i].first);
            } else {
                ans *= st2.size();
                ans %= mod;
                st2.erase(st2.begin());
            }        
        } else {
            if (st1.empty()) {
                st2.insert(obj[i].first);
            } else {
                ans *= st1.size();
                ans %= mod;
                st1.erase(st1.begin());
            }     
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    solve();
    return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User bluenote
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1239 Byte
Status AC
Exec Time 59 ms
Memory 6512 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 36 ms 1908 KB
001.txt AC 11 ms 892 KB
002.txt AC 15 ms 892 KB
003.txt AC 17 ms 1400 KB
004.txt AC 43 ms 2420 KB
005.txt AC 47 ms 2420 KB
006.txt AC 48 ms 2420 KB
007.txt AC 47 ms 2420 KB
008.txt AC 48 ms 2420 KB
009.txt AC 48 ms 2420 KB
010.txt AC 59 ms 6512 KB
011.txt AC 44 ms 2420 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB