#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100, mod = 1e9 + 7;
int a[N], b[N];
int dp[N][N * N * 3];
int n;
int solveTestCase() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
vector<int> v = {0};
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++)
v.push_back(a[i] + j), v.push_back(a[i] - j), v.push_back(b[i] + j), v.push_back(b[i] - j);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = 0; i < n; i++) {
a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
}
dp[0][0] = 1;
for (int i = a[0]; i <= b[0]; i++)
dp[0][i] = 1;
for (int i = 1; i < n; i++) {
dp[i][0] = 1;
int sum = 0;
for (int j = 0; j < a[i]; j++)
dp[i][j] = dp[i - 1][j], sum += dp[i - 1][j], sum %= mod;
for (int j = b[i] + 1; j < N * N * 3; j++)
dp[i][j] = dp[i - 1][j];
for (int j = a[i]; j <= b[i]; j++)
sum += dp[i - 1][j], sum %= mod, dp[i][j] = sum;
}
int ans = 0;
for (int i = 1; i < N * N * 3; i++)
ans += dp[n - 1][i], ans %= mod;
cout << ans;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--)
solveTestCase();
}
Compilation message
boat.cpp: In function 'long long int solveTestCase()':
boat.cpp:50:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
24180 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |