Submission #2641668


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

typedef pair<ll,ll> P;

ll n;
P a[200000];
ll ca,cb;
ll mod = 1e9 + 7;
int main(){
    cin >> n;
    REP(i,n){
        ll b;
        cin >> b;
        a[i] = P(b,0);
    }
    REP(i,n) {
        ll b;
        cin >> b;
        a[i + n] = P(b,1);
    }

    sort(a,a+2*n);

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

Submission Info

Submission Time
Task A - 1D Matching
User kyawakyawa
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1285 Byte
Status AC
Exec Time 97 ms
Memory 3328 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 58 ms 2176 KB
001.txt AC 22 ms 896 KB
002.txt AC 30 ms 1152 KB
003.txt AC 33 ms 1280 KB
004.txt AC 85 ms 3072 KB
005.txt AC 96 ms 3328 KB
006.txt AC 96 ms 3328 KB
007.txt AC 96 ms 3328 KB
008.txt AC 96 ms 3328 KB
009.txt AC 97 ms 3328 KB
010.txt AC 95 ms 3328 KB
011.txt AC 95 ms 3328 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB