#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000 + 5;
const int MOD = 1e9 + 7;
const int INV2 = 5e8 + 4;
int N,ans;
vector<int> a(MAX), b(MAX), ways(2*MAX), newWays(2*MAX), bin; //ways[i] = ways of ending between bin[i] and bin[i+1]-1
vector<vector<int>> Z(MAX);
vector<int> invs(MAX,-1);
int exp(int a, int e) {
if (e == 0) return 1;
if (e%2 == 1) return a * exp(a,e-1) % MOD;
int temp = exp(a,e/2);
return temp * temp % MOD;
}
int inv(int k) {
if (invs[k] != -1) return invs[k];
int D = 1;
for (int i = 0; i < k; i++) {
D *= i+1;
D %= MOD;
}
return invs[k] = exp(D,MOD-2);
}
int choose(int n, int k) {
int N = 1;
for (int i = 0; i < k; i++) {
N *= (n-i);
N %= MOD;
}
return N * inv(k) % MOD;
}
int calc(int sz, vector<int> &z) {
assert(z.size());
int res = 0;
for (int i = 1; i <= z.size(); i++) {
res += choose(sz+i-1,i) * z[z.size()-i] % MOD;
res %= MOD;
}
return res;
}
main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
b[i]++;
bin.push_back(a[i]);
bin.push_back(b[i]);
}
sort(bin.begin(),bin.end());
bin.erase(unique(bin.begin(),bin.end()),bin.end());
for (int i = 0; i < N; i++) {
int pre = 1, k = 0;
for (; bin[k] < a[i]; k++) {pre += ways[k]; pre %= MOD;}
for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
int sz = bin[k+1] - bin[k];
Z[k].push_back(pre);
newWays[k] = calc(sz,Z[k]);
pre += ways[k];
pre %= MOD;
}
ways = newWays;
}
for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]; ans %= MOD;}
cout << (ans < 0 ? ans + MOD : ans) << "\n";
return 0;
}
Compilation message
boat.cpp: In function 'long long int calc(long long int, std::vector<long long int>&)':
boat.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i <= z.size(); i++) {
~~^~~~~~~~~~~
boat.cpp: At global scope:
boat.cpp:52:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
boat.cpp: In function 'int main()':
boat.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
~~~~^~~~~~~~~~~~
boat.cpp:80:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]; ans %= MOD;}
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Execution timed out |
2043 ms |
1964 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
12 ms |
512 KB |
Output is correct |
4 |
Correct |
12 ms |
512 KB |
Output is correct |
5 |
Correct |
16 ms |
540 KB |
Output is correct |
6 |
Correct |
47 ms |
632 KB |
Output is correct |
7 |
Correct |
45 ms |
512 KB |
Output is correct |
8 |
Correct |
45 ms |
512 KB |
Output is correct |
9 |
Correct |
48 ms |
512 KB |
Output is correct |
10 |
Correct |
46 ms |
512 KB |
Output is correct |
11 |
Correct |
15 ms |
512 KB |
Output is correct |
12 |
Correct |
9 ms |
512 KB |
Output is correct |
13 |
Correct |
13 ms |
512 KB |
Output is correct |
14 |
Correct |
12 ms |
512 KB |
Output is correct |
15 |
Correct |
14 ms |
512 KB |
Output is correct |
16 |
Correct |
12 ms |
512 KB |
Output is correct |
17 |
Correct |
8 ms |
512 KB |
Output is correct |
18 |
Correct |
8 ms |
512 KB |
Output is correct |
19 |
Correct |
8 ms |
512 KB |
Output is correct |
20 |
Correct |
11 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Execution timed out |
2043 ms |
1964 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |