#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int L, R;
std::cin >> L >> R;
std::map<int, int> stamps;
while (R--) {
int X;
std::cin >> X;
std::vector<int> W(X);
for (auto &e : W) std::cin >> e;
std::vector<int> sumW(X + 1);
for (int i = 0; i < X; ++i) sumW[i + 1] = sumW[i] + W[i];
auto calcSum = [&](int l, int r) {
return sumW[r] - sumW[l];
};
std::map<int, int> rls;
for (int i = 0; i <= X; ++i) {
const auto l = calcSum(0, i), r = L - calcSum(i, X);
++rls[l];
--rls[r];
}
int val = 0, lastPos = 0;
for (const auto &[p, v] : rls) {
if (val == 0) {
++stamps[lastPos];
--stamps[p];
}
val += v;
lastPos = p;
}
}
int val = 0, lastPos = 0, answer = 0;
for (const auto &[p, v] : stamps) {
if (val != 0) answer += p - lastPos;
val += v;
lastPos = p;
}
std::cout << answer << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
144 ms |
6060 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
453 ms |
25764 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
28940 KB |
Output is correct |
2 |
Correct |
33 ms |
8720 KB |
Output is correct |
3 |
Correct |
33 ms |
5888 KB |
Output is correct |
4 |
Correct |
213 ms |
33484 KB |
Output is correct |
5 |
Correct |
71 ms |
19156 KB |
Output is correct |
6 |
Correct |
147 ms |
29644 KB |
Output is correct |
7 |
Correct |
3 ms |
972 KB |
Output is correct |
8 |
Correct |
183 ms |
29448 KB |
Output is correct |
9 |
Correct |
118 ms |
18744 KB |
Output is correct |
10 |
Correct |
288 ms |
36648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
28940 KB |
Output is correct |
2 |
Correct |
33 ms |
8720 KB |
Output is correct |
3 |
Correct |
33 ms |
5888 KB |
Output is correct |
4 |
Correct |
213 ms |
33484 KB |
Output is correct |
5 |
Correct |
71 ms |
19156 KB |
Output is correct |
6 |
Correct |
147 ms |
29644 KB |
Output is correct |
7 |
Correct |
3 ms |
972 KB |
Output is correct |
8 |
Correct |
183 ms |
29448 KB |
Output is correct |
9 |
Correct |
118 ms |
18744 KB |
Output is correct |
10 |
Correct |
288 ms |
36648 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
489 ms |
22388 KB |
Output is correct |
22 |
Correct |
82 ms |
6476 KB |
Output is correct |
23 |
Correct |
46 ms |
6572 KB |
Output is correct |
24 |
Correct |
214 ms |
21760 KB |
Output is correct |
25 |
Correct |
491 ms |
22288 KB |
Output is correct |
26 |
Correct |
166 ms |
12564 KB |
Output is correct |
27 |
Correct |
72 ms |
5448 KB |
Output is correct |
28 |
Correct |
475 ms |
22184 KB |
Output is correct |
29 |
Correct |
472 ms |
22396 KB |
Output is correct |
30 |
Correct |
150 ms |
17488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
144 ms |
6060 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
453 ms |
25764 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
172 ms |
28940 KB |
Output is correct |
22 |
Correct |
33 ms |
8720 KB |
Output is correct |
23 |
Correct |
33 ms |
5888 KB |
Output is correct |
24 |
Correct |
213 ms |
33484 KB |
Output is correct |
25 |
Correct |
71 ms |
19156 KB |
Output is correct |
26 |
Correct |
147 ms |
29644 KB |
Output is correct |
27 |
Correct |
3 ms |
972 KB |
Output is correct |
28 |
Correct |
183 ms |
29448 KB |
Output is correct |
29 |
Correct |
118 ms |
18744 KB |
Output is correct |
30 |
Correct |
288 ms |
36648 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
316 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
489 ms |
22388 KB |
Output is correct |
42 |
Correct |
82 ms |
6476 KB |
Output is correct |
43 |
Correct |
46 ms |
6572 KB |
Output is correct |
44 |
Correct |
214 ms |
21760 KB |
Output is correct |
45 |
Correct |
491 ms |
22288 KB |
Output is correct |
46 |
Correct |
166 ms |
12564 KB |
Output is correct |
47 |
Correct |
72 ms |
5448 KB |
Output is correct |
48 |
Correct |
475 ms |
22184 KB |
Output is correct |
49 |
Correct |
472 ms |
22396 KB |
Output is correct |
50 |
Correct |
150 ms |
17488 KB |
Output is correct |
51 |
Correct |
61 ms |
9704 KB |
Output is correct |
52 |
Correct |
533 ms |
28364 KB |
Output is correct |
53 |
Correct |
510 ms |
28028 KB |
Output is correct |
54 |
Correct |
110 ms |
9260 KB |
Output is correct |
55 |
Correct |
336 ms |
21964 KB |
Output is correct |
56 |
Correct |
192 ms |
20328 KB |
Output is correct |
57 |
Correct |
226 ms |
15932 KB |
Output is correct |
58 |
Correct |
542 ms |
29156 KB |
Output is correct |
59 |
Correct |
159 ms |
11952 KB |
Output is correct |
60 |
Correct |
217 ms |
14700 KB |
Output is correct |