Submission #3926461
Source Code Expand
#include<iostream> #include<vector> #include<algorithm> #include<queue> #include<tuple> using namespace std; const long long MOD = (long long)1e9 + 7; int main(){ int n; cin >> n; vector<pair<int, int>> c(2 * n); for(int i = 0; i < n; i++){ int x; cin >> x; c[i] = {x, 0}; } for(int i = 0; i < n; i++){ int x; cin >> x; c[i + n] = {x, 1}; } sort(begin(c), end(c)); long long ans = 1; queue<int> a, b; for(int i = 0; i < 2 * n; i++){ int x, y; tie(x, y) = c[i]; if(y == 0){ if(b.empty()){ a.push(x); }else{ ans *= b.size(); ans %= MOD; b.pop(); } }else{ if(a.empty()){ b.push(x); }else{ ans *= a.size(); ans %= MOD; a.pop(); } } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | lucky3977 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1063 Byte |
Status | AC |
Exec Time | 99 ms |
Memory | 2176 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
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 | 59 ms | 1152 KB |
001.txt | AC | 22 ms | 640 KB |
002.txt | AC | 30 ms | 768 KB |
003.txt | AC | 33 ms | 768 KB |
004.txt | AC | 86 ms | 1664 KB |
005.txt | AC | 99 ms | 1792 KB |
006.txt | AC | 96 ms | 1792 KB |
007.txt | AC | 97 ms | 1792 KB |
008.txt | AC | 97 ms | 1792 KB |
009.txt | AC | 97 ms | 1792 KB |
010.txt | AC | 96 ms | 2176 KB |
011.txt | AC | 96 ms | 1792 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 1 ms | 256 KB |