#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
const int MAXN=510, INF=1000000009, MOD=1000000007;
int n, m, le[MAXN], ri[MAXN], dp[MAXN][MAXN], sum[MAXN][MAXN];
vector<int> pt;
int main(){
scanf("%d", &n);
forn(i, n){
scanf("%d %d", le+i, ri+i);
pt.PB(le[i]), pt.PB(ri[i]);
}
pt.PB(-1), pt.PB(INF);
sort(pt.begin(), pt.end());
pt.erase(unique(pt.begin(), pt.end()), pt.end());
m = pt.size();
forn(i, n) forsn(j, 1, m){
if(pt[j]<=ri[i] && pt[j]>=le[i]){
dp[i][j]=1;
forn(k, i){
dp[i][j] = ((ll)dp[i][j] + (ll)sum[k][j-1] + ((ll)(min(ri[k]+1, pt[j]) - max(pt[j-1], le[k])))*dp[k][j-1])%MOD;
}
}
sum[i][j]=(sum[i][j-1]+((ll)(min(ri[i]+1, pt[j]) - max(pt[j-1], le[i])))*dp[i][j-1])%MOD;
}
int ans=0;
forn(i, n) ans=(ans+sum[i][m-1])%MOD;
printf("%d\n", ans);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
boat.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d %d", le+i, ri+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2260 KB |
Output is correct |
2 |
Correct |
4 ms |
2248 KB |
Output is correct |
3 |
Correct |
4 ms |
2260 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
4 ms |
2260 KB |
Output is correct |
6 |
Correct |
4 ms |
2260 KB |
Output is correct |
7 |
Correct |
4 ms |
2260 KB |
Output is correct |
8 |
Correct |
4 ms |
2260 KB |
Output is correct |
9 |
Correct |
4 ms |
2260 KB |
Output is correct |
10 |
Correct |
4 ms |
2236 KB |
Output is correct |
11 |
Correct |
4 ms |
2260 KB |
Output is correct |
12 |
Correct |
4 ms |
2260 KB |
Output is correct |
13 |
Correct |
4 ms |
2260 KB |
Output is correct |
14 |
Correct |
4 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
2312 KB |
Output is correct |
16 |
Correct |
3 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2224 KB |
Output is correct |
18 |
Correct |
2 ms |
2232 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2260 KB |
Output is correct |
2 |
Correct |
4 ms |
2248 KB |
Output is correct |
3 |
Correct |
4 ms |
2260 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
4 ms |
2260 KB |
Output is correct |
6 |
Correct |
4 ms |
2260 KB |
Output is correct |
7 |
Correct |
4 ms |
2260 KB |
Output is correct |
8 |
Correct |
4 ms |
2260 KB |
Output is correct |
9 |
Correct |
4 ms |
2260 KB |
Output is correct |
10 |
Correct |
4 ms |
2236 KB |
Output is correct |
11 |
Correct |
4 ms |
2260 KB |
Output is correct |
12 |
Correct |
4 ms |
2260 KB |
Output is correct |
13 |
Correct |
4 ms |
2260 KB |
Output is correct |
14 |
Correct |
4 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
2312 KB |
Output is correct |
16 |
Correct |
3 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2224 KB |
Output is correct |
18 |
Correct |
2 ms |
2232 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Incorrect |
183 ms |
2204 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2260 KB |
Output is correct |
2 |
Correct |
4 ms |
2248 KB |
Output is correct |
3 |
Correct |
4 ms |
2260 KB |
Output is correct |
4 |
Correct |
4 ms |
2260 KB |
Output is correct |
5 |
Correct |
4 ms |
2260 KB |
Output is correct |
6 |
Correct |
4 ms |
2260 KB |
Output is correct |
7 |
Correct |
4 ms |
2260 KB |
Output is correct |
8 |
Correct |
4 ms |
2260 KB |
Output is correct |
9 |
Correct |
4 ms |
2260 KB |
Output is correct |
10 |
Correct |
4 ms |
2236 KB |
Output is correct |
11 |
Correct |
4 ms |
2260 KB |
Output is correct |
12 |
Correct |
4 ms |
2260 KB |
Output is correct |
13 |
Correct |
4 ms |
2260 KB |
Output is correct |
14 |
Correct |
4 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
2312 KB |
Output is correct |
16 |
Correct |
3 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2224 KB |
Output is correct |
18 |
Correct |
2 ms |
2232 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Incorrect |
183 ms |
2204 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |