#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
// fin(task),fou(task);
#endif
NHP
/// cin>>s1;
///modwwe
phongbeo();
}
vector<int> v;
int c[501][1001];
ib a[501];
int dp[501][1001];
int modI(int a, int m) {
return a<=1?a:(1-modI(m%a, a)*m)/a+m;
}
void phongbeo()
{
cin>>n;
for(int i=1; i<=n; i++)
cin>>a[i].a>>a[i].b,
v.pb(a[i].a-1),v.pb(a[i].b);
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end())-v.begin());
/// dp[0][i]=1;
for(int i=1; i<v.size(); ++i) {
c[1][i]=v[i]-v[i-1];
for(int j=2; j<=n; ++j)
c[j][i]=c[j-1][i]*(v[i]-v[i-1]+j-1)%mod2*modI(j, mod2)%mod2;
}
for(int i=0; i<v.size(); i++)
dp[0][i]=1;
/// dua het tu v[i-1] ->v[i]
for(int i=1; i<v.size(); i++)
{
for(int j=1; j<=n; j++)
{
dp[j][i]=dp[j][i-1];
s2=1;
if(a[j].a<=v[i-1]+1&&a[j].b>=v[i])
{
for(int z=j-1; z>=0; --z)
{
dp[j][i]=(dp[j][i]+(dp[z][i-1]*c[s2][i])%mod2)%mod2;
if(a[z].a<=v[i-1]+1&&a[z].b>=v[i])
s2++;
}
}
}
}
s3=0;
for(int j=1;j<=n;j++){
s3=s3+dp[j][v.size()-1];
}
cout<<s3%mod2;
}
Compilation message
boat.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
boat.cpp: In function 'void phongbeo()':
boat.cpp:71:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=1; i<v.size(); ++i) {
| ~^~~~~~~~~
boat.cpp:76:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i=0; i<v.size(); i++)
| ~^~~~~~~~~
boat.cpp:80:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int i=1; i<v.size(); i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
8284 KB |
Output is correct |
2 |
Correct |
16 ms |
8284 KB |
Output is correct |
3 |
Correct |
18 ms |
8284 KB |
Output is correct |
4 |
Correct |
17 ms |
8148 KB |
Output is correct |
5 |
Correct |
15 ms |
8144 KB |
Output is correct |
6 |
Correct |
17 ms |
8284 KB |
Output is correct |
7 |
Correct |
16 ms |
8216 KB |
Output is correct |
8 |
Correct |
16 ms |
8316 KB |
Output is correct |
9 |
Correct |
15 ms |
8284 KB |
Output is correct |
10 |
Correct |
16 ms |
8152 KB |
Output is correct |
11 |
Correct |
16 ms |
8156 KB |
Output is correct |
12 |
Correct |
16 ms |
8160 KB |
Output is correct |
13 |
Correct |
17 ms |
8256 KB |
Output is correct |
14 |
Correct |
15 ms |
8280 KB |
Output is correct |
15 |
Correct |
16 ms |
8284 KB |
Output is correct |
16 |
Correct |
5 ms |
7004 KB |
Output is correct |
17 |
Correct |
6 ms |
7188 KB |
Output is correct |
18 |
Correct |
4 ms |
7004 KB |
Output is correct |
19 |
Correct |
5 ms |
7004 KB |
Output is correct |
20 |
Correct |
4 ms |
7004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
8284 KB |
Output is correct |
2 |
Correct |
16 ms |
8284 KB |
Output is correct |
3 |
Correct |
18 ms |
8284 KB |
Output is correct |
4 |
Correct |
17 ms |
8148 KB |
Output is correct |
5 |
Correct |
15 ms |
8144 KB |
Output is correct |
6 |
Correct |
17 ms |
8284 KB |
Output is correct |
7 |
Correct |
16 ms |
8216 KB |
Output is correct |
8 |
Correct |
16 ms |
8316 KB |
Output is correct |
9 |
Correct |
15 ms |
8284 KB |
Output is correct |
10 |
Correct |
16 ms |
8152 KB |
Output is correct |
11 |
Correct |
16 ms |
8156 KB |
Output is correct |
12 |
Correct |
16 ms |
8160 KB |
Output is correct |
13 |
Correct |
17 ms |
8256 KB |
Output is correct |
14 |
Correct |
15 ms |
8280 KB |
Output is correct |
15 |
Correct |
16 ms |
8284 KB |
Output is correct |
16 |
Correct |
5 ms |
7004 KB |
Output is correct |
17 |
Correct |
6 ms |
7188 KB |
Output is correct |
18 |
Correct |
4 ms |
7004 KB |
Output is correct |
19 |
Correct |
5 ms |
7004 KB |
Output is correct |
20 |
Correct |
4 ms |
7004 KB |
Output is correct |
21 |
Correct |
178 ms |
8276 KB |
Output is correct |
22 |
Correct |
172 ms |
8276 KB |
Output is correct |
23 |
Correct |
161 ms |
8276 KB |
Output is correct |
24 |
Correct |
170 ms |
8296 KB |
Output is correct |
25 |
Correct |
169 ms |
8276 KB |
Output is correct |
26 |
Correct |
235 ms |
8276 KB |
Output is correct |
27 |
Correct |
246 ms |
8268 KB |
Output is correct |
28 |
Correct |
235 ms |
8276 KB |
Output is correct |
29 |
Correct |
238 ms |
8304 KB |
Output is correct |
30 |
Correct |
17 ms |
8280 KB |
Output is correct |
31 |
Correct |
17 ms |
8284 KB |
Output is correct |
32 |
Correct |
17 ms |
8180 KB |
Output is correct |
33 |
Correct |
17 ms |
8284 KB |
Output is correct |
34 |
Correct |
16 ms |
8312 KB |
Output is correct |
35 |
Correct |
16 ms |
8276 KB |
Output is correct |
36 |
Correct |
17 ms |
8284 KB |
Output is correct |
37 |
Correct |
17 ms |
8284 KB |
Output is correct |
38 |
Correct |
18 ms |
8284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
3 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
4956 KB |
Output is correct |
5 |
Correct |
3 ms |
4956 KB |
Output is correct |
6 |
Correct |
4 ms |
4956 KB |
Output is correct |
7 |
Correct |
3 ms |
5092 KB |
Output is correct |
8 |
Correct |
3 ms |
4956 KB |
Output is correct |
9 |
Correct |
4 ms |
4952 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
2 ms |
4916 KB |
Output is correct |
14 |
Correct |
2 ms |
4996 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Correct |
2 ms |
4956 KB |
Output is correct |
18 |
Correct |
2 ms |
4956 KB |
Output is correct |
19 |
Correct |
2 ms |
4956 KB |
Output is correct |
20 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
8284 KB |
Output is correct |
2 |
Correct |
16 ms |
8284 KB |
Output is correct |
3 |
Correct |
18 ms |
8284 KB |
Output is correct |
4 |
Correct |
17 ms |
8148 KB |
Output is correct |
5 |
Correct |
15 ms |
8144 KB |
Output is correct |
6 |
Correct |
17 ms |
8284 KB |
Output is correct |
7 |
Correct |
16 ms |
8216 KB |
Output is correct |
8 |
Correct |
16 ms |
8316 KB |
Output is correct |
9 |
Correct |
15 ms |
8284 KB |
Output is correct |
10 |
Correct |
16 ms |
8152 KB |
Output is correct |
11 |
Correct |
16 ms |
8156 KB |
Output is correct |
12 |
Correct |
16 ms |
8160 KB |
Output is correct |
13 |
Correct |
17 ms |
8256 KB |
Output is correct |
14 |
Correct |
15 ms |
8280 KB |
Output is correct |
15 |
Correct |
16 ms |
8284 KB |
Output is correct |
16 |
Correct |
5 ms |
7004 KB |
Output is correct |
17 |
Correct |
6 ms |
7188 KB |
Output is correct |
18 |
Correct |
4 ms |
7004 KB |
Output is correct |
19 |
Correct |
5 ms |
7004 KB |
Output is correct |
20 |
Correct |
4 ms |
7004 KB |
Output is correct |
21 |
Correct |
178 ms |
8276 KB |
Output is correct |
22 |
Correct |
172 ms |
8276 KB |
Output is correct |
23 |
Correct |
161 ms |
8276 KB |
Output is correct |
24 |
Correct |
170 ms |
8296 KB |
Output is correct |
25 |
Correct |
169 ms |
8276 KB |
Output is correct |
26 |
Correct |
235 ms |
8276 KB |
Output is correct |
27 |
Correct |
246 ms |
8268 KB |
Output is correct |
28 |
Correct |
235 ms |
8276 KB |
Output is correct |
29 |
Correct |
238 ms |
8304 KB |
Output is correct |
30 |
Correct |
17 ms |
8280 KB |
Output is correct |
31 |
Correct |
17 ms |
8284 KB |
Output is correct |
32 |
Correct |
17 ms |
8180 KB |
Output is correct |
33 |
Correct |
17 ms |
8284 KB |
Output is correct |
34 |
Correct |
16 ms |
8312 KB |
Output is correct |
35 |
Correct |
16 ms |
8276 KB |
Output is correct |
36 |
Correct |
17 ms |
8284 KB |
Output is correct |
37 |
Correct |
17 ms |
8284 KB |
Output is correct |
38 |
Correct |
18 ms |
8284 KB |
Output is correct |
39 |
Correct |
3 ms |
4956 KB |
Output is correct |
40 |
Correct |
2 ms |
4956 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
3 ms |
4956 KB |
Output is correct |
44 |
Correct |
4 ms |
4956 KB |
Output is correct |
45 |
Correct |
3 ms |
5092 KB |
Output is correct |
46 |
Correct |
3 ms |
4956 KB |
Output is correct |
47 |
Correct |
4 ms |
4952 KB |
Output is correct |
48 |
Correct |
3 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
2 ms |
4956 KB |
Output is correct |
51 |
Correct |
2 ms |
4916 KB |
Output is correct |
52 |
Correct |
2 ms |
4996 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
2 ms |
4956 KB |
Output is correct |
56 |
Correct |
2 ms |
4956 KB |
Output is correct |
57 |
Correct |
2 ms |
4956 KB |
Output is correct |
58 |
Correct |
2 ms |
4956 KB |
Output is correct |
59 |
Correct |
192 ms |
8276 KB |
Output is correct |
60 |
Correct |
183 ms |
8252 KB |
Output is correct |
61 |
Correct |
178 ms |
8264 KB |
Output is correct |
62 |
Correct |
190 ms |
8276 KB |
Output is correct |
63 |
Correct |
190 ms |
8240 KB |
Output is correct |
64 |
Correct |
268 ms |
8276 KB |
Output is correct |
65 |
Correct |
272 ms |
8276 KB |
Output is correct |
66 |
Correct |
273 ms |
8272 KB |
Output is correct |
67 |
Correct |
271 ms |
8276 KB |
Output is correct |
68 |
Correct |
270 ms |
8276 KB |
Output is correct |
69 |
Correct |
149 ms |
8276 KB |
Output is correct |
70 |
Correct |
145 ms |
8276 KB |
Output is correct |
71 |
Correct |
149 ms |
8276 KB |
Output is correct |
72 |
Correct |
151 ms |
8276 KB |
Output is correct |
73 |
Correct |
158 ms |
8276 KB |
Output is correct |
74 |
Correct |
37 ms |
6996 KB |
Output is correct |
75 |
Correct |
36 ms |
7004 KB |
Output is correct |
76 |
Correct |
37 ms |
7008 KB |
Output is correct |
77 |
Correct |
39 ms |
6968 KB |
Output is correct |
78 |
Correct |
39 ms |
7060 KB |
Output is correct |