# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
883087 |
2023-12-04T13:34:49 Z |
KN200711 |
Boat (APIO16_boat) |
C++14 |
|
866 ms |
1876 KB |
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
const ll MOD = 1e9 + 7;
vector<int> seg[1100];
int l[1100], r[1100], len[1100];
bool V[501];
int num;
ll pref[1100], ad[1100], inv[1100];
ll fast(ll a, int b) {
if(b == 0) return 1ll;
if(b == 1) return a;
ll K = fast(a, b / 2);
K *= K;
K %= MOD;
if(b&1) {
K *= a;
K %= MOD;
}
return K;
}
void build() {
inv[0] = 1;
for(int i=1;i<1100;i++) {
inv[i] = fast(i, MOD - 2);
}
}
void fx(ll &a, ll c, ll d) {
a *= c;
a %= MOD;
a *= inv[d];
a %= MOD;
}
int main() {
build();
int N;
scanf("%d", &N);
vector< pair<int, int> > arr;
arr.clear();
for(int i=1;i<=N;i++) {
int a, b;
scanf("%d %d", &a, &b);
arr.push_back(make_pair(a, i));
arr.push_back(make_pair(b + 1, -i));
}
sort(arr.begin(), arr.end());
int lst;
for(int i=0;i<arr.size();i++) {
if(i > 0 && arr[i].fi != arr[i - 1].fi) {
l[num] = lst;
r[num] = arr[i].fi - 1;
len[num] = r[num] - l[num] + 1;
for(int k=1;k<=N;k++) {
if(V[k]) seg[num].push_back(k);
}
num++;
}
if(arr[i].se < 0) V[-arr[i].se] = 0;
else V[arr[i].se] = 1;
lst = arr[i].fi;
}
for(int i=0;i<=N;i++) pref[i] = 1ll;
for(int i=0;i<num;i++) {
// cout<<l[i]<<" "<<r[i]<<endl;
for(int k=1;k<=N;k++) ad[k] = 0ll;
for(int k=1;k<=seg[i].size();k++) {
ll as = 0ll;
if(k == 1) {
as = len[i];
} else if(len[i] >= 2) {
ll v = 1ll;
fx(v, len[i], 1ll);
fx(v, len[i] - 1, 2ll);
for(int c=0;;c++) {
as += v;
as %= MOD;
if(len[i] < c + 2) break;
if(k < c + 2) break;
fx(v, len[i] - c - 2ll, c + 3ll);
fx(v, k - c - 2ll, c + 1ll);
}
}
// cout<<"as : "<<i<<" "<<k<<" "<<as<<endl;
for(int c=0;c+k-1<seg[i].size();c++) {
ll D = as * pref[seg[i][c] - 1];
D %= MOD;
ad[seg[i][c + k - 1]] += D;
ad[seg[i][c + k - 1]] %= MOD;
}
}
ll kp = 0ll;
for(int k = 1;k<=N;k++) {
// cout<<i<<" "<<k<<" "<<ad[k]<<endl;
kp += ad[k];
kp %= MOD;
pref[k] += kp;
pref[k] %= MOD;
}
}
pref[N]--;
if(pref[N] < 0) pref[N] += MOD;
printf("%lld\n", pref[N]);
}
Compilation message
boat.cpp: In function 'int main()':
boat.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<arr.size();i++) {
| ~^~~~~~~~~~~
boat.cpp:78:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int k=1;k<=seg[i].size();k++) {
| ~^~~~~~~~~~~~~~~
boat.cpp:96:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int c=0;c+k-1<seg[i].size();c++) {
| ~~~~~^~~~~~~~~~~~~~
boat.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
boat.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
70 ms |
1296 KB |
Output is correct |
22 |
Correct |
67 ms |
1340 KB |
Output is correct |
23 |
Correct |
59 ms |
1228 KB |
Output is correct |
24 |
Correct |
66 ms |
1116 KB |
Output is correct |
25 |
Correct |
68 ms |
1276 KB |
Output is correct |
26 |
Correct |
135 ms |
1876 KB |
Output is correct |
27 |
Correct |
137 ms |
1628 KB |
Output is correct |
28 |
Correct |
135 ms |
1652 KB |
Output is correct |
29 |
Correct |
136 ms |
1648 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
548 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
348 KB |
Output is correct |
38 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
348 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
7 ms |
348 KB |
Output is correct |
10 |
Correct |
7 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
344 KB |
Output is correct |
13 |
Correct |
4 ms |
348 KB |
Output is correct |
14 |
Correct |
4 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
70 ms |
1296 KB |
Output is correct |
22 |
Correct |
67 ms |
1340 KB |
Output is correct |
23 |
Correct |
59 ms |
1228 KB |
Output is correct |
24 |
Correct |
66 ms |
1116 KB |
Output is correct |
25 |
Correct |
68 ms |
1276 KB |
Output is correct |
26 |
Correct |
135 ms |
1876 KB |
Output is correct |
27 |
Correct |
137 ms |
1628 KB |
Output is correct |
28 |
Correct |
135 ms |
1652 KB |
Output is correct |
29 |
Correct |
136 ms |
1648 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
3 ms |
548 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
348 KB |
Output is correct |
36 |
Correct |
3 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
348 KB |
Output is correct |
38 |
Correct |
3 ms |
348 KB |
Output is correct |
39 |
Correct |
4 ms |
348 KB |
Output is correct |
40 |
Correct |
2 ms |
348 KB |
Output is correct |
41 |
Correct |
3 ms |
348 KB |
Output is correct |
42 |
Correct |
3 ms |
348 KB |
Output is correct |
43 |
Correct |
4 ms |
348 KB |
Output is correct |
44 |
Correct |
7 ms |
348 KB |
Output is correct |
45 |
Correct |
7 ms |
348 KB |
Output is correct |
46 |
Correct |
8 ms |
348 KB |
Output is correct |
47 |
Correct |
7 ms |
348 KB |
Output is correct |
48 |
Correct |
7 ms |
348 KB |
Output is correct |
49 |
Correct |
4 ms |
348 KB |
Output is correct |
50 |
Correct |
3 ms |
344 KB |
Output is correct |
51 |
Correct |
4 ms |
348 KB |
Output is correct |
52 |
Correct |
4 ms |
348 KB |
Output is correct |
53 |
Correct |
4 ms |
348 KB |
Output is correct |
54 |
Correct |
2 ms |
348 KB |
Output is correct |
55 |
Correct |
2 ms |
348 KB |
Output is correct |
56 |
Correct |
2 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
348 KB |
Output is correct |
58 |
Correct |
2 ms |
348 KB |
Output is correct |
59 |
Correct |
363 ms |
1372 KB |
Output is correct |
60 |
Correct |
324 ms |
1364 KB |
Output is correct |
61 |
Correct |
310 ms |
1116 KB |
Output is correct |
62 |
Correct |
376 ms |
1492 KB |
Output is correct |
63 |
Correct |
347 ms |
1116 KB |
Output is correct |
64 |
Correct |
855 ms |
1824 KB |
Output is correct |
65 |
Correct |
858 ms |
1820 KB |
Output is correct |
66 |
Correct |
866 ms |
1824 KB |
Output is correct |
67 |
Correct |
862 ms |
1824 KB |
Output is correct |
68 |
Correct |
854 ms |
1820 KB |
Output is correct |
69 |
Correct |
310 ms |
1296 KB |
Output is correct |
70 |
Correct |
318 ms |
1116 KB |
Output is correct |
71 |
Correct |
315 ms |
1300 KB |
Output is correct |
72 |
Correct |
333 ms |
1304 KB |
Output is correct |
73 |
Correct |
338 ms |
1304 KB |
Output is correct |
74 |
Correct |
43 ms |
604 KB |
Output is correct |
75 |
Correct |
39 ms |
604 KB |
Output is correct |
76 |
Correct |
42 ms |
604 KB |
Output is correct |
77 |
Correct |
42 ms |
604 KB |
Output is correct |
78 |
Correct |
44 ms |
604 KB |
Output is correct |