# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
111237 |
2019-05-14T11:56:54 Z |
tictaccat |
Boat (APIO16_boat) |
C++14 |
|
418 ms |
11128 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000 + 5;
const int MOD = 1e9 + 7;
const int INV2 = 5e8 + 4;
int N,ans;
vector<int> a(MAX), b(MAX), ways(2*MAX), newWays(2*MAX), bin; //ways[i] = ways of ending between bin[i] and bin[i+1]-1
vector<vector<int>> Z(MAX), val(MAX,vector<int>(MAX));
vector<int> invs(MAX,-1);
int exp(int a, int e) {
if (e == 0) return 1;
if (e%2 == 1) return a * exp(a,e-1) % MOD;
int temp = exp(a,e/2);
return temp * temp % MOD;
}
int inv(int k) {
return exp(k,MOD-2);
}
int pre(int k) {
int res = 0;
int sz = bin[k+1] - bin[k];
val[k][0] = 1;
for (int i = 1; i <= N; i++) {
val[k][i] = val[k][i-1] * (sz+i-1) % MOD * inv(i) % MOD;
}
return res;
}
int calc(int k) {
int res = 0;
for (int i = 1; i <= Z[k].size(); i++) {
res += val[k][i] * Z[k][Z[k].size()-i] % MOD;
res %= MOD;
}
return res;
}
main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i];
b[i]++;
bin.push_back(a[i]);
bin.push_back(b[i]);
}
bin.push_back(2);
sort(bin.begin(),bin.end());
bin.erase(unique(bin.begin(),bin.end()),bin.end());
for (int i = 0; i < bin.size(); i++) pre(i);
for (int i = 0; i < N; i++) {
// cout << i << "\n";
int pre = 1, k = 0;
for (; bin[k] < a[i]; k++) {pre += ways[k]; pre %= MOD;}
for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
Z[k].push_back(pre);
newWays[k] = calc(k);
pre += ways[k];
pre %= MOD;
}
ways = newWays;
//cout << ways[0] << "\n";
}
for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]; ans %= MOD;}
cout << (ans < 0 ? ans + MOD : ans) << "\n";
return 0;
}
Compilation message
boat.cpp: In function 'long long int calc(long long int)':
boat.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i <= Z[k].size(); i++) {
~~^~~~~~~~~~~~~~
boat.cpp: At global scope:
boat.cpp:46:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
boat.cpp: In function 'int main()':
boat.cpp:62:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < bin.size(); i++) pre(i);
~~^~~~~~~~~~~~
boat.cpp:68:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (; k+1 < bin.size() && bin[k+1] <= b[i]; k++) {
~~~~^~~~~~~~~~~~
boat.cpp:78:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < bin.size()-1; k++) {ans += ways[k]; ans %= MOD;}
~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
8440 KB |
Output is correct |
2 |
Correct |
150 ms |
8320 KB |
Output is correct |
3 |
Correct |
165 ms |
8320 KB |
Output is correct |
4 |
Correct |
177 ms |
8516 KB |
Output is correct |
5 |
Correct |
157 ms |
8320 KB |
Output is correct |
6 |
Correct |
155 ms |
8424 KB |
Output is correct |
7 |
Correct |
152 ms |
8424 KB |
Output is correct |
8 |
Correct |
167 ms |
8424 KB |
Output is correct |
9 |
Correct |
147 ms |
8420 KB |
Output is correct |
10 |
Correct |
148 ms |
8320 KB |
Output is correct |
11 |
Correct |
148 ms |
8384 KB |
Output is correct |
12 |
Correct |
156 ms |
8420 KB |
Output is correct |
13 |
Correct |
152 ms |
8388 KB |
Output is correct |
14 |
Correct |
148 ms |
8320 KB |
Output is correct |
15 |
Correct |
171 ms |
8320 KB |
Output is correct |
16 |
Correct |
36 ms |
8320 KB |
Output is correct |
17 |
Correct |
37 ms |
8320 KB |
Output is correct |
18 |
Correct |
39 ms |
8320 KB |
Output is correct |
19 |
Correct |
36 ms |
8320 KB |
Output is correct |
20 |
Correct |
37 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
8440 KB |
Output is correct |
2 |
Correct |
150 ms |
8320 KB |
Output is correct |
3 |
Correct |
165 ms |
8320 KB |
Output is correct |
4 |
Correct |
177 ms |
8516 KB |
Output is correct |
5 |
Correct |
157 ms |
8320 KB |
Output is correct |
6 |
Correct |
155 ms |
8424 KB |
Output is correct |
7 |
Correct |
152 ms |
8424 KB |
Output is correct |
8 |
Correct |
167 ms |
8424 KB |
Output is correct |
9 |
Correct |
147 ms |
8420 KB |
Output is correct |
10 |
Correct |
148 ms |
8320 KB |
Output is correct |
11 |
Correct |
148 ms |
8384 KB |
Output is correct |
12 |
Correct |
156 ms |
8420 KB |
Output is correct |
13 |
Correct |
152 ms |
8388 KB |
Output is correct |
14 |
Correct |
148 ms |
8320 KB |
Output is correct |
15 |
Correct |
171 ms |
8320 KB |
Output is correct |
16 |
Correct |
36 ms |
8320 KB |
Output is correct |
17 |
Correct |
37 ms |
8320 KB |
Output is correct |
18 |
Correct |
39 ms |
8320 KB |
Output is correct |
19 |
Correct |
36 ms |
8320 KB |
Output is correct |
20 |
Correct |
37 ms |
8320 KB |
Output is correct |
21 |
Correct |
227 ms |
10056 KB |
Output is correct |
22 |
Correct |
242 ms |
10184 KB |
Output is correct |
23 |
Correct |
215 ms |
9980 KB |
Output is correct |
24 |
Correct |
233 ms |
10104 KB |
Output is correct |
25 |
Correct |
247 ms |
10048 KB |
Output is correct |
26 |
Correct |
358 ms |
10616 KB |
Output is correct |
27 |
Correct |
341 ms |
10808 KB |
Output is correct |
28 |
Correct |
328 ms |
10744 KB |
Output is correct |
29 |
Correct |
310 ms |
10632 KB |
Output is correct |
30 |
Correct |
150 ms |
8448 KB |
Output is correct |
31 |
Correct |
154 ms |
8404 KB |
Output is correct |
32 |
Correct |
168 ms |
8396 KB |
Output is correct |
33 |
Correct |
153 ms |
8440 KB |
Output is correct |
34 |
Correct |
154 ms |
8320 KB |
Output is correct |
35 |
Correct |
156 ms |
8400 KB |
Output is correct |
36 |
Correct |
157 ms |
8424 KB |
Output is correct |
37 |
Correct |
165 ms |
8320 KB |
Output is correct |
38 |
Correct |
163 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
8368 KB |
Output is correct |
2 |
Correct |
19 ms |
8448 KB |
Output is correct |
3 |
Correct |
15 ms |
8448 KB |
Output is correct |
4 |
Correct |
14 ms |
8448 KB |
Output is correct |
5 |
Correct |
16 ms |
8440 KB |
Output is correct |
6 |
Correct |
15 ms |
8448 KB |
Output is correct |
7 |
Correct |
16 ms |
8448 KB |
Output is correct |
8 |
Correct |
15 ms |
8448 KB |
Output is correct |
9 |
Correct |
18 ms |
8448 KB |
Output is correct |
10 |
Correct |
19 ms |
8448 KB |
Output is correct |
11 |
Correct |
18 ms |
8448 KB |
Output is correct |
12 |
Correct |
18 ms |
8448 KB |
Output is correct |
13 |
Correct |
17 ms |
8372 KB |
Output is correct |
14 |
Correct |
15 ms |
8448 KB |
Output is correct |
15 |
Correct |
15 ms |
8448 KB |
Output is correct |
16 |
Correct |
14 ms |
8320 KB |
Output is correct |
17 |
Correct |
12 ms |
8448 KB |
Output is correct |
18 |
Correct |
12 ms |
8448 KB |
Output is correct |
19 |
Correct |
12 ms |
8448 KB |
Output is correct |
20 |
Correct |
14 ms |
8448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
161 ms |
8440 KB |
Output is correct |
2 |
Correct |
150 ms |
8320 KB |
Output is correct |
3 |
Correct |
165 ms |
8320 KB |
Output is correct |
4 |
Correct |
177 ms |
8516 KB |
Output is correct |
5 |
Correct |
157 ms |
8320 KB |
Output is correct |
6 |
Correct |
155 ms |
8424 KB |
Output is correct |
7 |
Correct |
152 ms |
8424 KB |
Output is correct |
8 |
Correct |
167 ms |
8424 KB |
Output is correct |
9 |
Correct |
147 ms |
8420 KB |
Output is correct |
10 |
Correct |
148 ms |
8320 KB |
Output is correct |
11 |
Correct |
148 ms |
8384 KB |
Output is correct |
12 |
Correct |
156 ms |
8420 KB |
Output is correct |
13 |
Correct |
152 ms |
8388 KB |
Output is correct |
14 |
Correct |
148 ms |
8320 KB |
Output is correct |
15 |
Correct |
171 ms |
8320 KB |
Output is correct |
16 |
Correct |
36 ms |
8320 KB |
Output is correct |
17 |
Correct |
37 ms |
8320 KB |
Output is correct |
18 |
Correct |
39 ms |
8320 KB |
Output is correct |
19 |
Correct |
36 ms |
8320 KB |
Output is correct |
20 |
Correct |
37 ms |
8320 KB |
Output is correct |
21 |
Correct |
227 ms |
10056 KB |
Output is correct |
22 |
Correct |
242 ms |
10184 KB |
Output is correct |
23 |
Correct |
215 ms |
9980 KB |
Output is correct |
24 |
Correct |
233 ms |
10104 KB |
Output is correct |
25 |
Correct |
247 ms |
10048 KB |
Output is correct |
26 |
Correct |
358 ms |
10616 KB |
Output is correct |
27 |
Correct |
341 ms |
10808 KB |
Output is correct |
28 |
Correct |
328 ms |
10744 KB |
Output is correct |
29 |
Correct |
310 ms |
10632 KB |
Output is correct |
30 |
Correct |
150 ms |
8448 KB |
Output is correct |
31 |
Correct |
154 ms |
8404 KB |
Output is correct |
32 |
Correct |
168 ms |
8396 KB |
Output is correct |
33 |
Correct |
153 ms |
8440 KB |
Output is correct |
34 |
Correct |
154 ms |
8320 KB |
Output is correct |
35 |
Correct |
156 ms |
8400 KB |
Output is correct |
36 |
Correct |
157 ms |
8424 KB |
Output is correct |
37 |
Correct |
165 ms |
8320 KB |
Output is correct |
38 |
Correct |
163 ms |
8320 KB |
Output is correct |
39 |
Correct |
16 ms |
8368 KB |
Output is correct |
40 |
Correct |
19 ms |
8448 KB |
Output is correct |
41 |
Correct |
15 ms |
8448 KB |
Output is correct |
42 |
Correct |
14 ms |
8448 KB |
Output is correct |
43 |
Correct |
16 ms |
8440 KB |
Output is correct |
44 |
Correct |
15 ms |
8448 KB |
Output is correct |
45 |
Correct |
16 ms |
8448 KB |
Output is correct |
46 |
Correct |
15 ms |
8448 KB |
Output is correct |
47 |
Correct |
18 ms |
8448 KB |
Output is correct |
48 |
Correct |
19 ms |
8448 KB |
Output is correct |
49 |
Correct |
18 ms |
8448 KB |
Output is correct |
50 |
Correct |
18 ms |
8448 KB |
Output is correct |
51 |
Correct |
17 ms |
8372 KB |
Output is correct |
52 |
Correct |
15 ms |
8448 KB |
Output is correct |
53 |
Correct |
15 ms |
8448 KB |
Output is correct |
54 |
Correct |
14 ms |
8320 KB |
Output is correct |
55 |
Correct |
12 ms |
8448 KB |
Output is correct |
56 |
Correct |
12 ms |
8448 KB |
Output is correct |
57 |
Correct |
12 ms |
8448 KB |
Output is correct |
58 |
Correct |
14 ms |
8448 KB |
Output is correct |
59 |
Correct |
271 ms |
10232 KB |
Output is correct |
60 |
Correct |
262 ms |
10024 KB |
Output is correct |
61 |
Correct |
242 ms |
10108 KB |
Output is correct |
62 |
Correct |
256 ms |
10488 KB |
Output is correct |
63 |
Correct |
285 ms |
9976 KB |
Output is correct |
64 |
Correct |
387 ms |
10968 KB |
Output is correct |
65 |
Correct |
388 ms |
11028 KB |
Output is correct |
66 |
Correct |
406 ms |
11076 KB |
Output is correct |
67 |
Correct |
418 ms |
11068 KB |
Output is correct |
68 |
Correct |
381 ms |
11128 KB |
Output is correct |
69 |
Correct |
249 ms |
9984 KB |
Output is correct |
70 |
Correct |
243 ms |
9976 KB |
Output is correct |
71 |
Correct |
265 ms |
10104 KB |
Output is correct |
72 |
Correct |
232 ms |
9976 KB |
Output is correct |
73 |
Correct |
293 ms |
10088 KB |
Output is correct |
74 |
Correct |
61 ms |
8696 KB |
Output is correct |
75 |
Correct |
54 ms |
8696 KB |
Output is correct |
76 |
Correct |
63 ms |
8824 KB |
Output is correct |
77 |
Correct |
53 ms |
8656 KB |
Output is correct |
78 |
Correct |
56 ms |
8824 KB |
Output is correct |