Submission #4923701


Source Code Expand

#include <bits/stdc++.h>

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<pii> a;
    for(int i = 0; i < n; ++i){
        int t;
        cin >> t;
        a.push_back({t, 0});
    }
    for(int i = 0; i < n; ++i){
        int t;
        cin >> t;
        a.push_back({t, 1});
    }
    sort(begin(a), end(a));

    int cnt_pc = 0, cnt_power = 0;
    ll ans = 1;
    for(int i = 0; i < 2 * n; ++i){
        if(a[i].second == 0){
            if(cnt_power == 0){
                ++cnt_pc;
            }
            else{
                ans *= cnt_power;
                ans %= MOD;
                --cnt_power;
            }
        }
        if(a[i].second == 1){
            if(cnt_pc == 0){
                ++cnt_power;
            }
            else{
                ans *= cnt_pc;
                ans %= MOD;
                --cnt_pc;
            }
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

Submission Info

Submission Time
Task A - 1D Matching
User hagyu_aya
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1516 Byte
Status AC
Exec Time 39 ms
Memory 2548 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 23 ms 1400 KB
001.txt AC 9 ms 892 KB
002.txt AC 12 ms 892 KB
003.txt AC 14 ms 1400 KB
004.txt AC 35 ms 2420 KB
005.txt AC 39 ms 2548 KB
006.txt AC 39 ms 2420 KB
007.txt AC 38 ms 2420 KB
008.txt AC 39 ms 2420 KB
009.txt AC 39 ms 2420 KB
010.txt AC 38 ms 2420 KB
011.txt AC 38 ms 2420 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB