#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=590;
const ll mod=1e9+7;
const ll inf=1e9+9;
inline void zarb(ll &a,long long b){a=((long long)a*b)%mod;}
inline ll zarbO(long long a,long long b){return (a*b)%mod;}
inline void jam(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
inline ll jamO(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
ll dp[maxn][maxn*2];
ll dppar[maxn][maxn*2];
ll f[maxn*2][maxn];
ll ent[maxn][maxn];
ll rev[maxn];
ll a[maxn];
ll b[maxn];
ll poww(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
zarb(ans,a);
}
b>>=1;
zarb(a,a);
}
return ans;
}
ll tmp[maxn];
void hesab(ll x,ll tol){
tmp[0]=1;
for(ll i=1;i<maxn;i++){
tmp[i]=zarbO(tmp[i-1],zarbO(tol-i+1,rev[i]));
}
for(ll t=0;t+1<maxn;t++){
for(ll i=0;i<=t;i++){
jam(f[x][t],zarbO(ent[t][i],tmp[i+1]));
}
}
}
int main(){
for(ll i=0;i<maxn;i++){
rev[i]=poww(i,mod-2);
}
ent[0][0]=1;
for(ll i=1;i<maxn;i++){
ent[i][0]=1;
ent[i][i]=1;
for(ll j=1;j<i;j++){
ent[i][j]=jamO(ent[i-1][j],ent[i-1][j-1]);
}
}
ll n;
cin>>n;
vector<ll> vec;
vec.pb(0);
vec.pb(inf);
for(ll i=0;i<n;i++){
cin>>a[i]>>b[i];
vec.pb(a[i]);
vec.pb(b[i]+1);
}
{
sort(vec.begin(),vec.end());
auto it=unique(vec.begin(),vec.end());
vec.resize(it-vec.begin());
}
for(ll i=0;i+1<(ll)vec.size();i++){
ll tol=vec[i+1]-vec[i];
hesab(i,tol);
}
ll ans=0;
for(ll i=0;i<n;i++){
for(ll j=0;j+1<(ll)vec.size();j++){
//dp[i][j];
if(a[i]<=vec[j] && b[i]+1>=vec[j+1]){
ll tol=vec[j+1]-vec[j];
ll tedad=0;
for(ll z=i-1;z>=0;z--){
if(j)jam(dp[i][j],zarbO(dppar[z][j-1],f[j][tedad]));
tedad+=(a[z]<=vec[j] && b[z]+1>=vec[j+1]);
}
jam(dp[i][j],f[j][tedad]);
}
}
dppar[i][0]=dp[i][0];
for(ll j=1;j+1<(ll)vec.size();j++){
dppar[i][j]=jamO(dppar[i][j-1],dp[i][j]);
}
jam(ans,dppar[i][vec.size()-2]);
}
cout<<ans;
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:151:8: warning: unused variable 'tol' [-Wunused-variable]
ll tol=vec[j+1]-vec[j];
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
434 ms |
8184 KB |
Output is correct |
2 |
Correct |
433 ms |
8184 KB |
Output is correct |
3 |
Correct |
438 ms |
8164 KB |
Output is correct |
4 |
Correct |
446 ms |
8108 KB |
Output is correct |
5 |
Correct |
432 ms |
8260 KB |
Output is correct |
6 |
Correct |
455 ms |
8328 KB |
Output is correct |
7 |
Correct |
442 ms |
8468 KB |
Output is correct |
8 |
Correct |
471 ms |
8312 KB |
Output is correct |
9 |
Correct |
444 ms |
8604 KB |
Output is correct |
10 |
Correct |
431 ms |
8352 KB |
Output is correct |
11 |
Correct |
447 ms |
8440 KB |
Output is correct |
12 |
Correct |
441 ms |
8372 KB |
Output is correct |
13 |
Correct |
444 ms |
8392 KB |
Output is correct |
14 |
Correct |
439 ms |
8368 KB |
Output is correct |
15 |
Correct |
442 ms |
8312 KB |
Output is correct |
16 |
Correct |
86 ms |
6492 KB |
Output is correct |
17 |
Correct |
90 ms |
6516 KB |
Output is correct |
18 |
Correct |
88 ms |
6520 KB |
Output is correct |
19 |
Correct |
89 ms |
6520 KB |
Output is correct |
20 |
Correct |
90 ms |
6392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
434 ms |
8184 KB |
Output is correct |
2 |
Correct |
433 ms |
8184 KB |
Output is correct |
3 |
Correct |
438 ms |
8164 KB |
Output is correct |
4 |
Correct |
446 ms |
8108 KB |
Output is correct |
5 |
Correct |
432 ms |
8260 KB |
Output is correct |
6 |
Correct |
455 ms |
8328 KB |
Output is correct |
7 |
Correct |
442 ms |
8468 KB |
Output is correct |
8 |
Correct |
471 ms |
8312 KB |
Output is correct |
9 |
Correct |
444 ms |
8604 KB |
Output is correct |
10 |
Correct |
431 ms |
8352 KB |
Output is correct |
11 |
Correct |
447 ms |
8440 KB |
Output is correct |
12 |
Correct |
441 ms |
8372 KB |
Output is correct |
13 |
Correct |
444 ms |
8392 KB |
Output is correct |
14 |
Correct |
439 ms |
8368 KB |
Output is correct |
15 |
Correct |
442 ms |
8312 KB |
Output is correct |
16 |
Correct |
86 ms |
6492 KB |
Output is correct |
17 |
Correct |
90 ms |
6516 KB |
Output is correct |
18 |
Correct |
88 ms |
6520 KB |
Output is correct |
19 |
Correct |
89 ms |
6520 KB |
Output is correct |
20 |
Correct |
90 ms |
6392 KB |
Output is correct |
21 |
Correct |
871 ms |
8384 KB |
Output is correct |
22 |
Correct |
813 ms |
8456 KB |
Output is correct |
23 |
Correct |
779 ms |
8492 KB |
Output is correct |
24 |
Correct |
812 ms |
8312 KB |
Output is correct |
25 |
Correct |
808 ms |
8436 KB |
Output is correct |
26 |
Correct |
932 ms |
8404 KB |
Output is correct |
27 |
Correct |
961 ms |
8696 KB |
Output is correct |
28 |
Correct |
1181 ms |
8584 KB |
Output is correct |
29 |
Correct |
997 ms |
8480 KB |
Output is correct |
30 |
Correct |
433 ms |
8316 KB |
Output is correct |
31 |
Correct |
431 ms |
8332 KB |
Output is correct |
32 |
Correct |
444 ms |
8440 KB |
Output is correct |
33 |
Correct |
430 ms |
8568 KB |
Output is correct |
34 |
Correct |
431 ms |
8440 KB |
Output is correct |
35 |
Correct |
426 ms |
8204 KB |
Output is correct |
36 |
Correct |
433 ms |
8360 KB |
Output is correct |
37 |
Correct |
428 ms |
8176 KB |
Output is correct |
38 |
Correct |
446 ms |
8076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
3064 KB |
Output is correct |
2 |
Correct |
91 ms |
3132 KB |
Output is correct |
3 |
Correct |
92 ms |
3064 KB |
Output is correct |
4 |
Correct |
98 ms |
3036 KB |
Output is correct |
5 |
Correct |
92 ms |
3064 KB |
Output is correct |
6 |
Correct |
93 ms |
3092 KB |
Output is correct |
7 |
Correct |
95 ms |
3064 KB |
Output is correct |
8 |
Correct |
101 ms |
3064 KB |
Output is correct |
9 |
Correct |
95 ms |
3064 KB |
Output is correct |
10 |
Correct |
94 ms |
3064 KB |
Output is correct |
11 |
Correct |
94 ms |
3032 KB |
Output is correct |
12 |
Correct |
92 ms |
3136 KB |
Output is correct |
13 |
Correct |
94 ms |
3192 KB |
Output is correct |
14 |
Correct |
92 ms |
3036 KB |
Output is correct |
15 |
Correct |
95 ms |
3064 KB |
Output is correct |
16 |
Correct |
57 ms |
2936 KB |
Output is correct |
17 |
Correct |
60 ms |
2808 KB |
Output is correct |
18 |
Correct |
67 ms |
2852 KB |
Output is correct |
19 |
Correct |
56 ms |
2808 KB |
Output is correct |
20 |
Correct |
59 ms |
2808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
434 ms |
8184 KB |
Output is correct |
2 |
Correct |
433 ms |
8184 KB |
Output is correct |
3 |
Correct |
438 ms |
8164 KB |
Output is correct |
4 |
Correct |
446 ms |
8108 KB |
Output is correct |
5 |
Correct |
432 ms |
8260 KB |
Output is correct |
6 |
Correct |
455 ms |
8328 KB |
Output is correct |
7 |
Correct |
442 ms |
8468 KB |
Output is correct |
8 |
Correct |
471 ms |
8312 KB |
Output is correct |
9 |
Correct |
444 ms |
8604 KB |
Output is correct |
10 |
Correct |
431 ms |
8352 KB |
Output is correct |
11 |
Correct |
447 ms |
8440 KB |
Output is correct |
12 |
Correct |
441 ms |
8372 KB |
Output is correct |
13 |
Correct |
444 ms |
8392 KB |
Output is correct |
14 |
Correct |
439 ms |
8368 KB |
Output is correct |
15 |
Correct |
442 ms |
8312 KB |
Output is correct |
16 |
Correct |
86 ms |
6492 KB |
Output is correct |
17 |
Correct |
90 ms |
6516 KB |
Output is correct |
18 |
Correct |
88 ms |
6520 KB |
Output is correct |
19 |
Correct |
89 ms |
6520 KB |
Output is correct |
20 |
Correct |
90 ms |
6392 KB |
Output is correct |
21 |
Correct |
871 ms |
8384 KB |
Output is correct |
22 |
Correct |
813 ms |
8456 KB |
Output is correct |
23 |
Correct |
779 ms |
8492 KB |
Output is correct |
24 |
Correct |
812 ms |
8312 KB |
Output is correct |
25 |
Correct |
808 ms |
8436 KB |
Output is correct |
26 |
Correct |
932 ms |
8404 KB |
Output is correct |
27 |
Correct |
961 ms |
8696 KB |
Output is correct |
28 |
Correct |
1181 ms |
8584 KB |
Output is correct |
29 |
Correct |
997 ms |
8480 KB |
Output is correct |
30 |
Correct |
433 ms |
8316 KB |
Output is correct |
31 |
Correct |
431 ms |
8332 KB |
Output is correct |
32 |
Correct |
444 ms |
8440 KB |
Output is correct |
33 |
Correct |
430 ms |
8568 KB |
Output is correct |
34 |
Correct |
431 ms |
8440 KB |
Output is correct |
35 |
Correct |
426 ms |
8204 KB |
Output is correct |
36 |
Correct |
433 ms |
8360 KB |
Output is correct |
37 |
Correct |
428 ms |
8176 KB |
Output is correct |
38 |
Correct |
446 ms |
8076 KB |
Output is correct |
39 |
Correct |
94 ms |
3064 KB |
Output is correct |
40 |
Correct |
91 ms |
3132 KB |
Output is correct |
41 |
Correct |
92 ms |
3064 KB |
Output is correct |
42 |
Correct |
98 ms |
3036 KB |
Output is correct |
43 |
Correct |
92 ms |
3064 KB |
Output is correct |
44 |
Correct |
93 ms |
3092 KB |
Output is correct |
45 |
Correct |
95 ms |
3064 KB |
Output is correct |
46 |
Correct |
101 ms |
3064 KB |
Output is correct |
47 |
Correct |
95 ms |
3064 KB |
Output is correct |
48 |
Correct |
94 ms |
3064 KB |
Output is correct |
49 |
Correct |
94 ms |
3032 KB |
Output is correct |
50 |
Correct |
92 ms |
3136 KB |
Output is correct |
51 |
Correct |
94 ms |
3192 KB |
Output is correct |
52 |
Correct |
92 ms |
3036 KB |
Output is correct |
53 |
Correct |
95 ms |
3064 KB |
Output is correct |
54 |
Correct |
57 ms |
2936 KB |
Output is correct |
55 |
Correct |
60 ms |
2808 KB |
Output is correct |
56 |
Correct |
67 ms |
2852 KB |
Output is correct |
57 |
Correct |
56 ms |
2808 KB |
Output is correct |
58 |
Correct |
59 ms |
2808 KB |
Output is correct |
59 |
Correct |
912 ms |
8712 KB |
Output is correct |
60 |
Correct |
878 ms |
8516 KB |
Output is correct |
61 |
Correct |
895 ms |
8592 KB |
Output is correct |
62 |
Correct |
1016 ms |
8696 KB |
Output is correct |
63 |
Correct |
949 ms |
8588 KB |
Output is correct |
64 |
Correct |
1072 ms |
8676 KB |
Output is correct |
65 |
Correct |
1054 ms |
8796 KB |
Output is correct |
66 |
Correct |
1057 ms |
8816 KB |
Output is correct |
67 |
Correct |
1094 ms |
8824 KB |
Output is correct |
68 |
Correct |
1074 ms |
8696 KB |
Output is correct |
69 |
Correct |
793 ms |
8584 KB |
Output is correct |
70 |
Correct |
768 ms |
8640 KB |
Output is correct |
71 |
Correct |
741 ms |
8756 KB |
Output is correct |
72 |
Correct |
755 ms |
8696 KB |
Output is correct |
73 |
Correct |
778 ms |
8736 KB |
Output is correct |
74 |
Correct |
200 ms |
6624 KB |
Output is correct |
75 |
Correct |
180 ms |
6616 KB |
Output is correct |
76 |
Correct |
178 ms |
6520 KB |
Output is correct |
77 |
Correct |
177 ms |
6648 KB |
Output is correct |
78 |
Correct |
181 ms |
6520 KB |
Output is correct |