#include <bits/stdc++.h>
using namespace std;
using db = long double;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;
template<typename Tuple, size_t... Is>
void print_tuple(const Tuple& t, index_sequence<Is...>) {
((cerr << (Is == 0 ? "{" : ", ") << get<Is>(t)), ...);
cerr << "}";
}
template<typename... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
print_tuple(t, index_sequence_for<Args...>{});
return os;
}
ostream& operator<<(ostream& os, string& s) {
for (char c : s) os << c;
return os;
}
template<template<typename> class Container, typename T>
ostream& operator<<(ostream& os, Container<T> o) {
os << "{";
int g = size(o);
for (auto i : o) os << i << ((--g) == 0 ? "" : ", ");
os << "}";
return os;
}
template<typename T, typename V>
ostream& operator<<(ostream& os, const pair<T, V> p) {
os << "{" << p.f << ", " << p.s << "}";
return os;
}
template <typename T, typename... V>
void printer(const char *names, T &&head, V &&...tail) {
int i = 0;
while (names[i] != '\0' && names[i] != ',') i++;
constexpr bool is_str = is_same_v<decay_t<T>, const char*>;
if constexpr (is_str) cerr << head; // ignore directly passed strings
else cerr.write(names, i) << " = " << head;
if constexpr (sizeof...(tail)) cerr << (is_str ? "" : ","), printer(names + i + 1, tail...);
else cerr << endl;
}
#ifdef LOCAL
#define dbg(...) std::cerr << __LINE__ << ": ", printer(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif
/*
instead, we want to count the # of lasers which are possible to not be blocked
for each laser, we just need to know if we can construct a configuration
where its not blocked
u can do the greedy strategy, where you pretend to slide each piece in each row to the left as much as possible,
and then sliding the rest to the right, and hoping u dont get blocked in the middle
this means we can just try each number of blocks aligned to the left on each row, and then range increment
the "gap" in the center, indicating that there is a configuration of the row such that light passes through
then, we just need to check which lights have a non-zero value over all rows
merge ranges, insert as events, then sweep
*/
main() {
cin.tie(0)->sync_with_stdio(0);
int cs, rs; cin >> cs >> rs;
map<int, int> evs;
evs[cs] = 0;
F0R (_, rs) {
int n; cin >> n;
vt<int> blox(n + 1);
F0R (i, n) cin >> blox[i + 1];
FOR (i, 1, n + 1) blox[i] += blox[i - 1];
int tot = accumulate(all(blox), 0);
int l = 0, r = 0; // inc exc
F0R (i, n + 1) {
int lhs = blox[i], rhs = blox.back() - blox[i];
int nl = lhs, nr = cs - rhs;
if (nl <= r) { // merge ranges
r = nr;
} else { // flush range to events
evs[l]++;
evs[r]--;
tie(l, r) = pi {nl, nr};
}
}
evs[l]++;
evs[r]--;
}
int ans = 0, last = 0, pfx = 0;
for (auto [c, diff] : evs) { // exc
if (pfx != rs) ans += c - last;
pfx += diff;
last = c;
}
cout << ans << endl;
}
Compilation message
lasers.cpp:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
90 | main() {
| ^~~~
lasers.cpp: In function 'int main()':
lasers.cpp:101:13: warning: unused variable 'tot' [-Wunused-variable]
101 | int tot = accumulate(all(blox), 0);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
103 ms |
6056 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
220 ms |
25688 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
16088 KB |
Output is correct |
2 |
Correct |
15 ms |
2920 KB |
Output is correct |
3 |
Correct |
8 ms |
2192 KB |
Output is correct |
4 |
Correct |
62 ms |
17960 KB |
Output is correct |
5 |
Correct |
22 ms |
7260 KB |
Output is correct |
6 |
Correct |
26 ms |
6108 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
36 ms |
7872 KB |
Output is correct |
9 |
Correct |
56 ms |
13056 KB |
Output is correct |
10 |
Correct |
85 ms |
19868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
456 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
16088 KB |
Output is correct |
2 |
Correct |
15 ms |
2920 KB |
Output is correct |
3 |
Correct |
8 ms |
2192 KB |
Output is correct |
4 |
Correct |
62 ms |
17960 KB |
Output is correct |
5 |
Correct |
22 ms |
7260 KB |
Output is correct |
6 |
Correct |
26 ms |
6108 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
36 ms |
7872 KB |
Output is correct |
9 |
Correct |
56 ms |
13056 KB |
Output is correct |
10 |
Correct |
85 ms |
19868 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
456 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
221 ms |
22356 KB |
Output is correct |
22 |
Correct |
42 ms |
6632 KB |
Output is correct |
23 |
Correct |
21 ms |
4956 KB |
Output is correct |
24 |
Correct |
63 ms |
15748 KB |
Output is correct |
25 |
Correct |
252 ms |
22356 KB |
Output is correct |
26 |
Correct |
99 ms |
12372 KB |
Output is correct |
27 |
Correct |
36 ms |
5476 KB |
Output is correct |
28 |
Correct |
220 ms |
22116 KB |
Output is correct |
29 |
Correct |
220 ms |
22356 KB |
Output is correct |
30 |
Correct |
47 ms |
11676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
452 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
103 ms |
6056 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
220 ms |
25688 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
73 ms |
16088 KB |
Output is correct |
22 |
Correct |
15 ms |
2920 KB |
Output is correct |
23 |
Correct |
8 ms |
2192 KB |
Output is correct |
24 |
Correct |
62 ms |
17960 KB |
Output is correct |
25 |
Correct |
22 ms |
7260 KB |
Output is correct |
26 |
Correct |
26 ms |
6108 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
36 ms |
7872 KB |
Output is correct |
29 |
Correct |
56 ms |
13056 KB |
Output is correct |
30 |
Correct |
85 ms |
19868 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
456 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
221 ms |
22356 KB |
Output is correct |
42 |
Correct |
42 ms |
6632 KB |
Output is correct |
43 |
Correct |
21 ms |
4956 KB |
Output is correct |
44 |
Correct |
63 ms |
15748 KB |
Output is correct |
45 |
Correct |
252 ms |
22356 KB |
Output is correct |
46 |
Correct |
99 ms |
12372 KB |
Output is correct |
47 |
Correct |
36 ms |
5476 KB |
Output is correct |
48 |
Correct |
220 ms |
22116 KB |
Output is correct |
49 |
Correct |
220 ms |
22356 KB |
Output is correct |
50 |
Correct |
47 ms |
11676 KB |
Output is correct |
51 |
Correct |
25 ms |
7288 KB |
Output is correct |
52 |
Correct |
247 ms |
28260 KB |
Output is correct |
53 |
Correct |
218 ms |
27988 KB |
Output is correct |
54 |
Correct |
57 ms |
9300 KB |
Output is correct |
55 |
Correct |
154 ms |
22228 KB |
Output is correct |
56 |
Correct |
69 ms |
16896 KB |
Output is correct |
57 |
Correct |
99 ms |
15832 KB |
Output is correct |
58 |
Correct |
248 ms |
29068 KB |
Output is correct |
59 |
Correct |
84 ms |
11860 KB |
Output is correct |
60 |
Correct |
105 ms |
14600 KB |
Output is correct |