#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int sz = 5e5+5;
ll l, n;
vector<pair<int, bool>> segs;
inline bool intersect(const pii& lhs, const pii& rhs) {
return (rhs.first - lhs.second <= 1);
}
int main() {
fast;
cin >> l >> n;
bool bad = 0;
while (n--) {
vector<int> v;
int x, tmp, rsum = 0, lsum = 0;
cin >> x;
foru(i, 0, x) {
cin >> tmp;
rsum += tmp;
v.pb(tmp);
}
if (rsum == l) {
bad = 1;
continue;
}
vector<pii> yes;
yes.pb({ 0,l - rsum - 1 });
lsum += v[0];
rsum -= v[0];
foru(i, 1, x + 1) {
pii inval = { lsum, l - rsum - 1 }, yb = yes.back();
if (intersect(yb, inval)) {
yes.back() = { yb.first,inval.second };
}
else {
yes.pb(inval);
}
if (i != x) {
lsum += v[i];
rsum -= v[i];
}
}
foru(i, 0, yes.size() - 1) {
segs.pb({ yes[i].second + 1,0 });
segs.pb({ yes[i + 1].first - 1,1 });
}
}
if (bad) {
cout << l << '\n';
return 0;
}
sort(segs.begin(), segs.end());
ll tot = 0, prvLit = -1;
int o = 0;
for (auto x : segs) {
if (!x.second) {
if (o == 0) {
prvLit = x.first;
}
o++;
}
else {
o--;
if (o == 0) {
tot += (x.first - prvLit + 1);
}
}
}
cout << tot << '\n';
return 0;
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:2:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
2 | #define foru(i, k, n) for (int i = k; i < n; i++)
......
62 | foru(i, 0, yes.size() - 1) {
| ~~~~~~~~~~~~~~~~~~~~
lasers.cpp:62:3: note: in expansion of macro 'foru'
62 | foru(i, 0, yes.size() - 1) {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
95 ms |
6152 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
200 ms |
9564 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
6732 KB |
Output is correct |
2 |
Correct |
7 ms |
1392 KB |
Output is correct |
3 |
Correct |
45 ms |
1480 KB |
Output is correct |
4 |
Correct |
77 ms |
7088 KB |
Output is correct |
5 |
Correct |
31 ms |
4752 KB |
Output is correct |
6 |
Correct |
44 ms |
3644 KB |
Output is correct |
7 |
Correct |
35 ms |
492 KB |
Output is correct |
8 |
Correct |
80 ms |
5192 KB |
Output is correct |
9 |
Correct |
33 ms |
6072 KB |
Output is correct |
10 |
Correct |
73 ms |
8068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
364 KB |
Output is correct |
2 |
Correct |
35 ms |
364 KB |
Output is correct |
3 |
Correct |
32 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
35 ms |
364 KB |
Output is correct |
8 |
Correct |
68 ms |
364 KB |
Output is correct |
9 |
Correct |
53 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
6732 KB |
Output is correct |
2 |
Correct |
7 ms |
1392 KB |
Output is correct |
3 |
Correct |
45 ms |
1480 KB |
Output is correct |
4 |
Correct |
77 ms |
7088 KB |
Output is correct |
5 |
Correct |
31 ms |
4752 KB |
Output is correct |
6 |
Correct |
44 ms |
3644 KB |
Output is correct |
7 |
Correct |
35 ms |
492 KB |
Output is correct |
8 |
Correct |
80 ms |
5192 KB |
Output is correct |
9 |
Correct |
33 ms |
6072 KB |
Output is correct |
10 |
Correct |
73 ms |
8068 KB |
Output is correct |
11 |
Correct |
34 ms |
364 KB |
Output is correct |
12 |
Correct |
35 ms |
364 KB |
Output is correct |
13 |
Correct |
32 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
35 ms |
364 KB |
Output is correct |
18 |
Correct |
68 ms |
364 KB |
Output is correct |
19 |
Correct |
53 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
319 ms |
8668 KB |
Output is correct |
22 |
Correct |
17 ms |
2148 KB |
Output is correct |
23 |
Correct |
19 ms |
2144 KB |
Output is correct |
24 |
Correct |
67 ms |
6804 KB |
Output is correct |
25 |
Correct |
245 ms |
8796 KB |
Output is correct |
26 |
Correct |
54 ms |
5848 KB |
Output is correct |
27 |
Correct |
24 ms |
2024 KB |
Output is correct |
28 |
Correct |
178 ms |
8668 KB |
Output is correct |
29 |
Correct |
244 ms |
8668 KB |
Output is correct |
30 |
Correct |
50 ms |
4208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
95 ms |
6152 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
200 ms |
9564 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
62 ms |
6732 KB |
Output is correct |
22 |
Correct |
7 ms |
1392 KB |
Output is correct |
23 |
Correct |
45 ms |
1480 KB |
Output is correct |
24 |
Correct |
77 ms |
7088 KB |
Output is correct |
25 |
Correct |
31 ms |
4752 KB |
Output is correct |
26 |
Correct |
44 ms |
3644 KB |
Output is correct |
27 |
Correct |
35 ms |
492 KB |
Output is correct |
28 |
Correct |
80 ms |
5192 KB |
Output is correct |
29 |
Correct |
33 ms |
6072 KB |
Output is correct |
30 |
Correct |
73 ms |
8068 KB |
Output is correct |
31 |
Correct |
34 ms |
364 KB |
Output is correct |
32 |
Correct |
35 ms |
364 KB |
Output is correct |
33 |
Correct |
32 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
35 ms |
364 KB |
Output is correct |
38 |
Correct |
68 ms |
364 KB |
Output is correct |
39 |
Correct |
53 ms |
304 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
319 ms |
8668 KB |
Output is correct |
42 |
Correct |
17 ms |
2148 KB |
Output is correct |
43 |
Correct |
19 ms |
2144 KB |
Output is correct |
44 |
Correct |
67 ms |
6804 KB |
Output is correct |
45 |
Correct |
245 ms |
8796 KB |
Output is correct |
46 |
Correct |
54 ms |
5848 KB |
Output is correct |
47 |
Correct |
24 ms |
2024 KB |
Output is correct |
48 |
Correct |
178 ms |
8668 KB |
Output is correct |
49 |
Correct |
244 ms |
8668 KB |
Output is correct |
50 |
Correct |
50 ms |
4208 KB |
Output is correct |
51 |
Correct |
56 ms |
2364 KB |
Output is correct |
52 |
Correct |
167 ms |
9948 KB |
Output is correct |
53 |
Correct |
262 ms |
9704 KB |
Output is correct |
54 |
Correct |
176 ms |
4064 KB |
Output is correct |
55 |
Correct |
161 ms |
7004 KB |
Output is correct |
56 |
Correct |
128 ms |
6568 KB |
Output is correct |
57 |
Correct |
67 ms |
6748 KB |
Output is correct |
58 |
Correct |
184 ms |
10004 KB |
Output is correct |
59 |
Correct |
46 ms |
3640 KB |
Output is correct |
60 |
Correct |
64 ms |
4692 KB |
Output is correct |