Submission #1837463


Source Code Expand

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int M = 1000000007;

//x^n mod M
typedef long long ull;
ull power(ull x, ull n, ull M){
	ull res = 1;
	if(n > 0){
		res = power(x, n / 2, M);
		if(n % 2 == 0) res = (res * res) % M;
		else res = (((res * res) % M) * x ) %M;
	}
	return res;
}

int main(){
	int n;
	cin >> n;

	vector<int> a(n), b(n);
	vector<pair<int, bool>> p(n * 2); //1 : PC, 0 : power supply
	rep(i,n){
		cin >> a[i] >> b[i];
	}

	rep(i,n){
		p[i] = make_pair(a[i], true);
		p[i + n] = make_pair(b[i], false);
	}

	sort(all(p));

	int cnt = 0, cur = -1;
	vector<int> v;
	rep(i,n){
		cnt += p[i].second ? 1 : -1;
		if(cnt == 0){
			v.emplace_back((i - cur) / 2);
			cur = i;
		}
	}

	//for(auto i : p){ cout << i.second << ' ' ; } cout << endl;

	long long ans = 1;
	for(auto i : v){
		//show(i)
		vector<long long> c(i);
		rep(j,i + 1){
			if(j == 0) c[j] = 1;
			else{
				c[j] = c[j - 1] * (i - (j - 1)) % M * power(j, M - 2, M) % M;
			}
		}

		long long m = 1;
		rep(j,i){
			m *= c[j];
			m %= M;
		}
		(ans *= m) %= M;
	}
	cout << ans << endl;
}

Submission Info

Submission Time
Task A - 1D Matching
User noy72
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1357 Byte
Status RE
Exec Time 190 ms
Memory 2560 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
WA × 1
AC × 1
WA × 1
RE × 12
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 RE 152 ms 1664 KB
001.txt RE 116 ms 896 KB
002.txt RE 124 ms 1024 KB
003.txt RE 137 ms 1152 KB
004.txt RE 181 ms 2304 KB
005.txt RE 190 ms 2560 KB
006.txt RE 189 ms 2560 KB
007.txt RE 188 ms 2560 KB
008.txt RE 189 ms 2560 KB
009.txt RE 190 ms 2560 KB
010.txt RE 188 ms 2560 KB
011.txt RE 189 ms 2560 KB
example0.txt WA 1 ms 256 KB
example1.txt AC 1 ms 256 KB