#include <bits/stdc++.h>
uint32_t PRIME = 1000000007;
std::vector<std::pair<uint32_t, uint32_t>> schools;
std::unordered_map<uint32_t, uint32_t> memo[500];
uint32_t count(int i, uint32_t min)
{
if (i >= schools.size())
return 1;
auto mIt = memo[i].find(min);
if (mIt != memo[i].end())
return mIt->second;
uint32_t c = count(i + 1, min);
for (uint32_t n = std::max(schools[i].first, min == 0 ? 0 : (min + 1)); n <= schools[i].second; n++)
{
c = (c + count(i + 1, n)) % PRIME;
}
memo[i].insert(std::make_pair(min, c));
return c;
}
int main()
{
int N;
std::cin >> N;
schools.resize(N);
for (int i = 0; i < N; i++)
{
std::cin >> schools[i].first;
std::cin >> schools[i].second;
}
std::cout << (count(0, 0) - 1) << std::endl;
}
Compilation message
boat.cpp: In function 'uint32_t count(int, uint32_t)':
boat.cpp:11:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (i >= schools.size())
~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
5880 KB |
Output is correct |
2 |
Correct |
49 ms |
5976 KB |
Output is correct |
3 |
Correct |
41 ms |
5976 KB |
Output is correct |
4 |
Correct |
59 ms |
5976 KB |
Output is correct |
5 |
Correct |
53 ms |
5976 KB |
Output is correct |
6 |
Correct |
57 ms |
6052 KB |
Output is correct |
7 |
Correct |
47 ms |
6052 KB |
Output is correct |
8 |
Correct |
62 ms |
6100 KB |
Output is correct |
9 |
Correct |
55 ms |
6100 KB |
Output is correct |
10 |
Correct |
74 ms |
6100 KB |
Output is correct |
11 |
Correct |
43 ms |
6100 KB |
Output is correct |
12 |
Correct |
55 ms |
6100 KB |
Output is correct |
13 |
Correct |
69 ms |
6100 KB |
Output is correct |
14 |
Correct |
50 ms |
6100 KB |
Output is correct |
15 |
Correct |
88 ms |
6124 KB |
Output is correct |
16 |
Correct |
13 ms |
6124 KB |
Output is correct |
17 |
Correct |
16 ms |
6124 KB |
Output is correct |
18 |
Correct |
17 ms |
6124 KB |
Output is correct |
19 |
Correct |
19 ms |
6124 KB |
Output is correct |
20 |
Correct |
13 ms |
6124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
5880 KB |
Output is correct |
2 |
Correct |
49 ms |
5976 KB |
Output is correct |
3 |
Correct |
41 ms |
5976 KB |
Output is correct |
4 |
Correct |
59 ms |
5976 KB |
Output is correct |
5 |
Correct |
53 ms |
5976 KB |
Output is correct |
6 |
Correct |
57 ms |
6052 KB |
Output is correct |
7 |
Correct |
47 ms |
6052 KB |
Output is correct |
8 |
Correct |
62 ms |
6100 KB |
Output is correct |
9 |
Correct |
55 ms |
6100 KB |
Output is correct |
10 |
Correct |
74 ms |
6100 KB |
Output is correct |
11 |
Correct |
43 ms |
6100 KB |
Output is correct |
12 |
Correct |
55 ms |
6100 KB |
Output is correct |
13 |
Correct |
69 ms |
6100 KB |
Output is correct |
14 |
Correct |
50 ms |
6100 KB |
Output is correct |
15 |
Correct |
88 ms |
6124 KB |
Output is correct |
16 |
Correct |
13 ms |
6124 KB |
Output is correct |
17 |
Correct |
16 ms |
6124 KB |
Output is correct |
18 |
Correct |
17 ms |
6124 KB |
Output is correct |
19 |
Correct |
19 ms |
6124 KB |
Output is correct |
20 |
Correct |
13 ms |
6124 KB |
Output is correct |
21 |
Execution timed out |
2047 ms |
6124 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2061 ms |
6124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
5880 KB |
Output is correct |
2 |
Correct |
49 ms |
5976 KB |
Output is correct |
3 |
Correct |
41 ms |
5976 KB |
Output is correct |
4 |
Correct |
59 ms |
5976 KB |
Output is correct |
5 |
Correct |
53 ms |
5976 KB |
Output is correct |
6 |
Correct |
57 ms |
6052 KB |
Output is correct |
7 |
Correct |
47 ms |
6052 KB |
Output is correct |
8 |
Correct |
62 ms |
6100 KB |
Output is correct |
9 |
Correct |
55 ms |
6100 KB |
Output is correct |
10 |
Correct |
74 ms |
6100 KB |
Output is correct |
11 |
Correct |
43 ms |
6100 KB |
Output is correct |
12 |
Correct |
55 ms |
6100 KB |
Output is correct |
13 |
Correct |
69 ms |
6100 KB |
Output is correct |
14 |
Correct |
50 ms |
6100 KB |
Output is correct |
15 |
Correct |
88 ms |
6124 KB |
Output is correct |
16 |
Correct |
13 ms |
6124 KB |
Output is correct |
17 |
Correct |
16 ms |
6124 KB |
Output is correct |
18 |
Correct |
17 ms |
6124 KB |
Output is correct |
19 |
Correct |
19 ms |
6124 KB |
Output is correct |
20 |
Correct |
13 ms |
6124 KB |
Output is correct |
21 |
Execution timed out |
2047 ms |
6124 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |