Submission #1837462


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;
		}
		show(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 1364 Byte
Status RE
Exec Time 209 ms
Memory 2944 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
WA × 2
WA × 2
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 166 ms 1920 KB
001.txt RE 122 ms 896 KB
002.txt RE 132 ms 1024 KB
003.txt RE 143 ms 1280 KB
004.txt RE 199 ms 2688 KB
005.txt RE 209 ms 2944 KB
006.txt RE 209 ms 2944 KB
007.txt RE 207 ms 2944 KB
008.txt RE 208 ms 2944 KB
009.txt RE 208 ms 2944 KB
010.txt RE 207 ms 2944 KB
011.txt RE 208 ms 2944 KB
example0.txt WA 1 ms 256 KB
example1.txt WA 1 ms 256 KB