Submission #3775704
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> ll POW(ll a, ll b){ if(b == 0) return 1LL; if(b == 1) return a; if(b%2 == 1) return (a*POW(a, b-1))%INF; ll x = POW(a, b/2); return (x*x)%INF; } 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]){ ans = (ans * fact[v[1]])%INF; ans = (ans * POW(fact[v[0]-v[1]], INF-2))%INF; v[0] = v[0]-v[1]+v[2]; v.erase(v.begin()+1); v.erase(v.begin()+1); } else if(v[0] < v[1]){ ans = (ans * fact[v[0]])%INF; ans = (ans * POW(fact[v[1]-v[0]], INF-2))%INF; v[1] -= v[0]; 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 | 1491 Byte |
Status | WA |
Exec Time | 1739 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 | 318 ms | 3324 KB |
001.txt | WA | 57 ms | 1920 KB |
002.txt | WA | 98 ms | 2176 KB |
003.txt | WA | 117 ms | 2300 KB |
004.txt | WA | 656 ms | 4344 KB |
005.txt | WA | 818 ms | 4728 KB |
006.txt | WA | 820 ms | 4728 KB |
007.txt | WA | 816 ms | 4728 KB |
008.txt | WA | 810 ms | 4728 KB |
009.txt | WA | 812 ms | 4728 KB |
010.txt | AC | 96 ms | 4096 KB |
011.txt | AC | 1739 ms | 4852 KB |
example0.txt | AC | 2 ms | 1024 KB |
example1.txt | AC | 2 ms | 1024 KB |