# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
110906 |
2019-05-13T05:24:23 Z |
TAISA_ |
Boat (APIO16_boat) |
C++14 |
|
956 ms |
8568 KB |
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
};
template <typename T>
bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for(int i = 0; i < v.size(); i++) {
os << v[i] << (i + 1 == v.size() ? "\n" : " ");
}
return os;
}
template <typename T>
vector<T> make_v(size_t a) {
return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
for(auto& e : t) {
fill_v(e, v);
}
};
ll mpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1){
res=res*x%MOD;
}
x=x*x%MOD;
n>>=1;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;cin>>n;
vector<ll> a(n+1),b(n+1),v,inv(n+10);
v.push_back(0);
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
v.push_back(a[i]);
v.push_back(b[i]+1);
}
for(int i=1;i<=n;i++){
inv[i]=mpow(i,MOD-2LL);
}
v.push_back(0);
sort(all(v));
v.erase(unique(all(v)),v.end());
for(int i=1;i<=n;i++){
a[i]=lower_bound(all(v),a[i])-v.begin();
b[i]=lower_bound(all(v),b[i]+1)-v.begin()-1;
}
int m=v.size();
auto dp=make_v<ll>(n+10,m+10);
auto sum=make_v<ll>(n+10,m+10);
dp[0][0]=1;
for(int j=0;j<=m;j++){
sum[0][j]=1;
}
ll ans=0;
for(int i=1;i<=n;i++){
for(int j=a[i];j<=b[i];j++){
ll c=v[j+1]-v[j],x=v[j+1]-v[j],y=1;
for(int k=i-1;k>=0;k--){
dp[i][j]+=c*sum[k][j-1]%MOD;
dp[i][j]%=MOD;
if(a[k]<=j&&j<=b[k]){
c*=(x+1LL)*inv[y+1]%MOD;
c%=MOD;
x++;
y++;
}
}
}
sum[i][0]=dp[i][0];
for(int j=1;j<=m;j++){
sum[i][j]=sum[i][j-1]+dp[i][j];
sum[i][j]%=MOD;
}
ans+=sum[i][m];
ans%=MOD;
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8448 KB |
Output is correct |
2 |
Correct |
18 ms |
8568 KB |
Output is correct |
3 |
Correct |
15 ms |
8448 KB |
Output is correct |
4 |
Correct |
15 ms |
8448 KB |
Output is correct |
5 |
Correct |
14 ms |
8448 KB |
Output is correct |
6 |
Correct |
13 ms |
8448 KB |
Output is correct |
7 |
Correct |
14 ms |
8448 KB |
Output is correct |
8 |
Correct |
13 ms |
8448 KB |
Output is correct |
9 |
Correct |
14 ms |
8448 KB |
Output is correct |
10 |
Correct |
14 ms |
8448 KB |
Output is correct |
11 |
Correct |
16 ms |
8448 KB |
Output is correct |
12 |
Correct |
14 ms |
8448 KB |
Output is correct |
13 |
Correct |
14 ms |
8448 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
15 |
Correct |
14 ms |
8448 KB |
Output is correct |
16 |
Correct |
5 ms |
1920 KB |
Output is correct |
17 |
Correct |
7 ms |
2048 KB |
Output is correct |
18 |
Correct |
5 ms |
1920 KB |
Output is correct |
19 |
Correct |
5 ms |
1920 KB |
Output is correct |
20 |
Correct |
7 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8448 KB |
Output is correct |
2 |
Correct |
18 ms |
8568 KB |
Output is correct |
3 |
Correct |
15 ms |
8448 KB |
Output is correct |
4 |
Correct |
15 ms |
8448 KB |
Output is correct |
5 |
Correct |
14 ms |
8448 KB |
Output is correct |
6 |
Correct |
13 ms |
8448 KB |
Output is correct |
7 |
Correct |
14 ms |
8448 KB |
Output is correct |
8 |
Correct |
13 ms |
8448 KB |
Output is correct |
9 |
Correct |
14 ms |
8448 KB |
Output is correct |
10 |
Correct |
14 ms |
8448 KB |
Output is correct |
11 |
Correct |
16 ms |
8448 KB |
Output is correct |
12 |
Correct |
14 ms |
8448 KB |
Output is correct |
13 |
Correct |
14 ms |
8448 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
15 |
Correct |
14 ms |
8448 KB |
Output is correct |
16 |
Correct |
5 ms |
1920 KB |
Output is correct |
17 |
Correct |
7 ms |
2048 KB |
Output is correct |
18 |
Correct |
5 ms |
1920 KB |
Output is correct |
19 |
Correct |
5 ms |
1920 KB |
Output is correct |
20 |
Correct |
7 ms |
1920 KB |
Output is correct |
21 |
Correct |
562 ms |
7816 KB |
Output is correct |
22 |
Correct |
526 ms |
7928 KB |
Output is correct |
23 |
Correct |
455 ms |
7928 KB |
Output is correct |
24 |
Correct |
503 ms |
7800 KB |
Output is correct |
25 |
Correct |
528 ms |
7800 KB |
Output is correct |
26 |
Correct |
584 ms |
7552 KB |
Output is correct |
27 |
Correct |
861 ms |
7672 KB |
Output is correct |
28 |
Correct |
670 ms |
7552 KB |
Output is correct |
29 |
Correct |
643 ms |
7564 KB |
Output is correct |
30 |
Correct |
13 ms |
8448 KB |
Output is correct |
31 |
Correct |
15 ms |
8448 KB |
Output is correct |
32 |
Correct |
15 ms |
8448 KB |
Output is correct |
33 |
Correct |
15 ms |
8448 KB |
Output is correct |
34 |
Correct |
15 ms |
8448 KB |
Output is correct |
35 |
Correct |
19 ms |
8448 KB |
Output is correct |
36 |
Correct |
15 ms |
8448 KB |
Output is correct |
37 |
Correct |
22 ms |
8448 KB |
Output is correct |
38 |
Correct |
17 ms |
8448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
6 ms |
768 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
6 ms |
768 KB |
Output is correct |
6 |
Correct |
7 ms |
640 KB |
Output is correct |
7 |
Correct |
7 ms |
640 KB |
Output is correct |
8 |
Correct |
7 ms |
768 KB |
Output is correct |
9 |
Correct |
9 ms |
768 KB |
Output is correct |
10 |
Correct |
26 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
6 ms |
640 KB |
Output is correct |
16 |
Correct |
4 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
512 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
8448 KB |
Output is correct |
2 |
Correct |
18 ms |
8568 KB |
Output is correct |
3 |
Correct |
15 ms |
8448 KB |
Output is correct |
4 |
Correct |
15 ms |
8448 KB |
Output is correct |
5 |
Correct |
14 ms |
8448 KB |
Output is correct |
6 |
Correct |
13 ms |
8448 KB |
Output is correct |
7 |
Correct |
14 ms |
8448 KB |
Output is correct |
8 |
Correct |
13 ms |
8448 KB |
Output is correct |
9 |
Correct |
14 ms |
8448 KB |
Output is correct |
10 |
Correct |
14 ms |
8448 KB |
Output is correct |
11 |
Correct |
16 ms |
8448 KB |
Output is correct |
12 |
Correct |
14 ms |
8448 KB |
Output is correct |
13 |
Correct |
14 ms |
8448 KB |
Output is correct |
14 |
Correct |
13 ms |
8448 KB |
Output is correct |
15 |
Correct |
14 ms |
8448 KB |
Output is correct |
16 |
Correct |
5 ms |
1920 KB |
Output is correct |
17 |
Correct |
7 ms |
2048 KB |
Output is correct |
18 |
Correct |
5 ms |
1920 KB |
Output is correct |
19 |
Correct |
5 ms |
1920 KB |
Output is correct |
20 |
Correct |
7 ms |
1920 KB |
Output is correct |
21 |
Correct |
562 ms |
7816 KB |
Output is correct |
22 |
Correct |
526 ms |
7928 KB |
Output is correct |
23 |
Correct |
455 ms |
7928 KB |
Output is correct |
24 |
Correct |
503 ms |
7800 KB |
Output is correct |
25 |
Correct |
528 ms |
7800 KB |
Output is correct |
26 |
Correct |
584 ms |
7552 KB |
Output is correct |
27 |
Correct |
861 ms |
7672 KB |
Output is correct |
28 |
Correct |
670 ms |
7552 KB |
Output is correct |
29 |
Correct |
643 ms |
7564 KB |
Output is correct |
30 |
Correct |
13 ms |
8448 KB |
Output is correct |
31 |
Correct |
15 ms |
8448 KB |
Output is correct |
32 |
Correct |
15 ms |
8448 KB |
Output is correct |
33 |
Correct |
15 ms |
8448 KB |
Output is correct |
34 |
Correct |
15 ms |
8448 KB |
Output is correct |
35 |
Correct |
19 ms |
8448 KB |
Output is correct |
36 |
Correct |
15 ms |
8448 KB |
Output is correct |
37 |
Correct |
22 ms |
8448 KB |
Output is correct |
38 |
Correct |
17 ms |
8448 KB |
Output is correct |
39 |
Correct |
5 ms |
768 KB |
Output is correct |
40 |
Correct |
6 ms |
640 KB |
Output is correct |
41 |
Correct |
6 ms |
768 KB |
Output is correct |
42 |
Correct |
5 ms |
640 KB |
Output is correct |
43 |
Correct |
6 ms |
768 KB |
Output is correct |
44 |
Correct |
7 ms |
640 KB |
Output is correct |
45 |
Correct |
7 ms |
640 KB |
Output is correct |
46 |
Correct |
7 ms |
768 KB |
Output is correct |
47 |
Correct |
9 ms |
768 KB |
Output is correct |
48 |
Correct |
26 ms |
640 KB |
Output is correct |
49 |
Correct |
5 ms |
640 KB |
Output is correct |
50 |
Correct |
4 ms |
640 KB |
Output is correct |
51 |
Correct |
6 ms |
768 KB |
Output is correct |
52 |
Correct |
5 ms |
640 KB |
Output is correct |
53 |
Correct |
6 ms |
640 KB |
Output is correct |
54 |
Correct |
4 ms |
512 KB |
Output is correct |
55 |
Correct |
4 ms |
640 KB |
Output is correct |
56 |
Correct |
4 ms |
512 KB |
Output is correct |
57 |
Correct |
5 ms |
640 KB |
Output is correct |
58 |
Correct |
5 ms |
640 KB |
Output is correct |
59 |
Correct |
625 ms |
8516 KB |
Output is correct |
60 |
Correct |
676 ms |
8540 KB |
Output is correct |
61 |
Correct |
473 ms |
8568 KB |
Output is correct |
62 |
Correct |
521 ms |
8568 KB |
Output is correct |
63 |
Correct |
639 ms |
8568 KB |
Output is correct |
64 |
Correct |
731 ms |
8568 KB |
Output is correct |
65 |
Correct |
793 ms |
8448 KB |
Output is correct |
66 |
Correct |
821 ms |
8568 KB |
Output is correct |
67 |
Correct |
825 ms |
8448 KB |
Output is correct |
68 |
Correct |
956 ms |
8568 KB |
Output is correct |
69 |
Correct |
415 ms |
8448 KB |
Output is correct |
70 |
Correct |
333 ms |
8448 KB |
Output is correct |
71 |
Correct |
422 ms |
8568 KB |
Output is correct |
72 |
Correct |
343 ms |
8568 KB |
Output is correct |
73 |
Correct |
364 ms |
8568 KB |
Output is correct |
74 |
Correct |
101 ms |
2012 KB |
Output is correct |
75 |
Correct |
88 ms |
2040 KB |
Output is correct |
76 |
Correct |
86 ms |
1920 KB |
Output is correct |
77 |
Correct |
92 ms |
2024 KB |
Output is correct |
78 |
Correct |
104 ms |
1964 KB |
Output is correct |