#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 500;
int const modulo = 1000000007;
class ModuloRing{
private:
void gcd(int a, int b, int &x, int &y){
if(b == 0){
x = 1;
y = 0;
} else {
gcd(b, a % b, x, y);
int aux = x;
x = y;
y = aux - a / b * y;
}
}
public:
int number;
ModuloRing(ll number_ = 0){
number = number_ % modulo;
}
ModuloRing operator + (ModuloRing a) {
return {number + a.number};
}
ModuloRing operator - (ModuloRing a) {
return {modulo + number - a.number};
}
ModuloRing operator * (ModuloRing a) {
return {1LL * number * a.number};
}
ModuloRing operator / (ModuloRing a) {
int x, y;
gcd(a.number, modulo, x, y);
x %= modulo;
if(x < 0)
x += modulo;
return 1LL * number * x;
}
};
map<int,int> code;
vector<int> dist;
int a[1 + nmax], b[1 + nmax];
void normalize(int n){
vector<int> temp;
temp.push_back(0);
for(int i = 1; i <= n; i++){
temp.push_back(a[i]);
temp.push_back(b[i]);
}
sort(temp.begin(), temp.end());
temp.erase(unique(temp.begin(), temp.end()), temp.end());
dist = temp;
for(int i = 0; i < temp.size(); i++)
code[temp[i]] = i;
for(int i = 1;i <= n; i++){
a[i] = code[a[i]];
b[i] = code[b[i]];
}
}
ModuloRing choose[5 + 2 * nmax][1 + nmax];
ModuloRing dp[5 + nmax][5 + 2 * nmax];
ModuloRing fact[5 + nmax];
void computefact(){
fact[0] = 1;
for(int i = 1;i <= nmax; i++)
fact[i] = fact[i - 1] * i;
}
ModuloRing comb(int n, int k){
if(n < k)
return 0;
if(n <= nmax)
return fact[n] / fact[k] / fact[n - k];
ModuloRing result(1);
for(int i = n - k + 1; i <= n; i++)
result = result * i;
for(int i = 1; i <= k; i++)
result = result / i;
return result;
}
int main()
{
int n;
cin >> n;
for(int i = 1;i <= n; i++) {
cin >> a[i] >> b[i];
b[i]++;
}
normalize(n);
computefact();
for(int i = 1; i < dist.size() - 1; i++) {
int d = dist[i + 1] - dist[i];
for(int h = 1;h <= n; h++) {
ModuloRing snap = comb(d, h);
for(int j = h; j <= n; j++)
choose[i][j] = choose[i][j] + comb(j - 1, h - 1) * snap;
}
}
for(int i = 0; i < dist.size() - 1; i++)
dp[0][i] = 1;
for(int i = 1;i <= n; i++){
for(int j = a[i]; j < b[i]; j++){
int _count = 1;
for(int i2 = i - 1; 0 <= i2; i2--){
dp[i][j] = dp[i][j] + dp[i2][j - 1] * choose[j][_count];
if(a[i2] <= j && j < b[i2])
_count++;
}
}
for(int j = 1; j < dist.size() - 1; j++) {
dp[i][j] = dp[i][j] + dp[i][j - 1];
}
}
ModuloRing result(0);
for(int i = 1;i <= n; i++)
result = result + dp[i][dist.size() - 2];
cout << result.number;
return 0;
}
/*
*/
Compilation message
boat.cpp: In function 'void normalize(int)':
boat.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < temp.size(); i++)
~~^~~~~~~~~~~~~
boat.cpp: In function 'int main()':
boat.cpp:113:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < dist.size() - 1; i++) {
~~^~~~~~~~~~~~~~~~~
boat.cpp:122:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < dist.size() - 1; i++)
~~^~~~~~~~~~~~~~~~~
boat.cpp:134:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j < dist.size() - 1; j++) {
~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2088 ms |
4352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2088 ms |
4352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
349 ms |
4352 KB |
Output is correct |
2 |
Correct |
350 ms |
4344 KB |
Output is correct |
3 |
Correct |
353 ms |
4332 KB |
Output is correct |
4 |
Correct |
352 ms |
4344 KB |
Output is correct |
5 |
Correct |
352 ms |
4224 KB |
Output is correct |
6 |
Correct |
349 ms |
4472 KB |
Output is correct |
7 |
Correct |
355 ms |
4224 KB |
Output is correct |
8 |
Correct |
355 ms |
4332 KB |
Output is correct |
9 |
Correct |
349 ms |
4224 KB |
Output is correct |
10 |
Correct |
348 ms |
4224 KB |
Output is correct |
11 |
Correct |
350 ms |
4224 KB |
Output is correct |
12 |
Correct |
348 ms |
4352 KB |
Output is correct |
13 |
Correct |
350 ms |
4472 KB |
Output is correct |
14 |
Correct |
348 ms |
4224 KB |
Output is correct |
15 |
Correct |
347 ms |
4472 KB |
Output is correct |
16 |
Correct |
198 ms |
4224 KB |
Output is correct |
17 |
Correct |
195 ms |
4344 KB |
Output is correct |
18 |
Correct |
197 ms |
4472 KB |
Output is correct |
19 |
Correct |
198 ms |
4224 KB |
Output is correct |
20 |
Correct |
192 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2088 ms |
4352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |