Submission #3775637
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define REP(i,m) for(int i=0; i<m; i++) #define FOR(i,n,m) for(int i=n; i<m; i++) #define INF 1000000007 #define INFL (1LL << 60) #define MOD 998244353 #define ALL(v) v.begin(),v.end() #define pb push_back #define ll long long int #define P pair<ll, ll> int main(){ int n; cin >> n; P p[2*n]; REP(i, n){ int a; cin >> a; p[i] = {a, 0}; } REP(i, n){ int a; cin >> a; p[n+i] = {a, 1}; } sort(p, p+2*n); vector<int> v; int c = 1; REP(i, 2*n-1){ if(p[i].second == p[i+1].second) c++; else{ v.pb(c); c = 1; } } v.pb(c); ll ans = 1; ll fact[100010]; fact[0] = 1; REP(i, 100009) fact[i+1] = (fact[i] * (i+1))%INF; while(v.size()!=0){ if(v[0] > v[1]){ v[0] = v[0]-v[1]+v[2]; ans = (ans * fact[v[1]])%INF; v.erase(v.begin()+1); v.erase(v.begin()+1); } else if(v[0] < v[1]){ v[1] -= v[0]; ans = (ans * fact[v[0]])%INF; v.erase(v.begin()); } else{ ans = (ans * fact[v[0]])%INF; v.erase(v.begin()); v.erase(v.begin()); } } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | A - 1D Matching |
User | EctoPlasma |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1219 Byte |
Status | WA |
Exec Time | 1727 ms |
Memory | 4852 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 312 ms | 3324 KB |
001.txt | WA | 54 ms | 1920 KB |
002.txt | WA | 94 ms | 2176 KB |
003.txt | WA | 112 ms | 2300 KB |
004.txt | WA | 645 ms | 4344 KB |
005.txt | WA | 804 ms | 4728 KB |
006.txt | WA | 808 ms | 4728 KB |
007.txt | WA | 802 ms | 4728 KB |
008.txt | WA | 799 ms | 4728 KB |
009.txt | WA | 799 ms | 4728 KB |
010.txt | AC | 97 ms | 4096 KB |
011.txt | AC | 1727 ms | 4852 KB |
example0.txt | AC | 2 ms | 1024 KB |
example1.txt | AC | 2 ms | 1024 KB |