#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 1e6 + 69, mxq = 1e5 + 5, sq = 500, mxv = 2e7 + 5;
//const int base = (1 <<18);
const int inf = 1e9 + 5, neg = -69420;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int x[9] = {0, 1, 1, -1, -1, 2, -2, 2, -2};
//const inty[9] = {0, 2, -2, 2, -2, 1, 1, -1, -1};
int n, l;
map<int, int>p;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("COMCAT.INP", "r", stdin);
//freopen("COMCAT.OUT", "w", stdout);
cin >> l >> n;
for(int i = 1; i <= n; i++){
int x; cin >> x;
vt<int>v(x);
ll tot = 0;
for(int j = 0; j < x; j++){
cin >> v[j]; tot += v[j];
}
if(tot == l)continue;
ll pref = 0;
vt<pll>seg;
for(int j = 0; j <= x; j++){
ll lpos = pref + 1, rpos = l - (tot - pref);
while(sz(seg) && lpos <= seg.back().se){
lpos = seg.back().fi; seg.pop_back();
}
seg.pb(mpp(lpos, rpos));
if(j < x)pref += v[j];
}
for(auto [lp, rp]: seg){
p[lp]++; p[rp + 1]--;
}
}
ll pref = 0, ans = 0, last = 0;
for(auto i: p){
//cout << i.fi << " " << i.se << "\n";
if(pref == n){
ans += i.fi - last;
}
last = i.fi; pref += i.se;
}
cout << l - ans;
return(0);
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:56:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto [lp, rp]: seg){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
68 ms |
6196 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 |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
319 ms |
25908 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
19124 KB |
Output is correct |
2 |
Correct |
11 ms |
3288 KB |
Output is correct |
3 |
Correct |
9 ms |
2448 KB |
Output is correct |
4 |
Correct |
88 ms |
23352 KB |
Output is correct |
5 |
Correct |
28 ms |
8668 KB |
Output is correct |
6 |
Correct |
34 ms |
7060 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
48 ms |
9032 KB |
Output is correct |
9 |
Correct |
60 ms |
14532 KB |
Output is correct |
10 |
Correct |
106 ms |
24936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
19124 KB |
Output is correct |
2 |
Correct |
11 ms |
3288 KB |
Output is correct |
3 |
Correct |
9 ms |
2448 KB |
Output is correct |
4 |
Correct |
88 ms |
23352 KB |
Output is correct |
5 |
Correct |
28 ms |
8668 KB |
Output is correct |
6 |
Correct |
34 ms |
7060 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
48 ms |
9032 KB |
Output is correct |
9 |
Correct |
60 ms |
14532 KB |
Output is correct |
10 |
Correct |
106 ms |
24936 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 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 |
328 ms |
22608 KB |
Output is correct |
22 |
Correct |
46 ms |
6484 KB |
Output is correct |
23 |
Correct |
20 ms |
5320 KB |
Output is correct |
24 |
Correct |
81 ms |
16440 KB |
Output is correct |
25 |
Correct |
314 ms |
22220 KB |
Output is correct |
26 |
Correct |
86 ms |
12368 KB |
Output is correct |
27 |
Correct |
32 ms |
5460 KB |
Output is correct |
28 |
Correct |
260 ms |
22360 KB |
Output is correct |
29 |
Correct |
274 ms |
22620 KB |
Output is correct |
30 |
Correct |
63 ms |
11840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
68 ms |
6196 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 |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
319 ms |
25908 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
86 ms |
19124 KB |
Output is correct |
22 |
Correct |
11 ms |
3288 KB |
Output is correct |
23 |
Correct |
9 ms |
2448 KB |
Output is correct |
24 |
Correct |
88 ms |
23352 KB |
Output is correct |
25 |
Correct |
28 ms |
8668 KB |
Output is correct |
26 |
Correct |
34 ms |
7060 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
48 ms |
9032 KB |
Output is correct |
29 |
Correct |
60 ms |
14532 KB |
Output is correct |
30 |
Correct |
106 ms |
24936 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
456 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
464 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
328 ms |
22608 KB |
Output is correct |
42 |
Correct |
46 ms |
6484 KB |
Output is correct |
43 |
Correct |
20 ms |
5320 KB |
Output is correct |
44 |
Correct |
81 ms |
16440 KB |
Output is correct |
45 |
Correct |
314 ms |
22220 KB |
Output is correct |
46 |
Correct |
86 ms |
12368 KB |
Output is correct |
47 |
Correct |
32 ms |
5460 KB |
Output is correct |
48 |
Correct |
260 ms |
22360 KB |
Output is correct |
49 |
Correct |
274 ms |
22620 KB |
Output is correct |
50 |
Correct |
63 ms |
11840 KB |
Output is correct |
51 |
Correct |
30 ms |
7464 KB |
Output is correct |
52 |
Correct |
345 ms |
28420 KB |
Output is correct |
53 |
Correct |
342 ms |
27984 KB |
Output is correct |
54 |
Correct |
60 ms |
9300 KB |
Output is correct |
55 |
Correct |
174 ms |
22220 KB |
Output is correct |
56 |
Correct |
84 ms |
16948 KB |
Output is correct |
57 |
Correct |
106 ms |
16220 KB |
Output is correct |
58 |
Correct |
404 ms |
29264 KB |
Output is correct |
59 |
Correct |
74 ms |
12112 KB |
Output is correct |
60 |
Correct |
95 ms |
14676 KB |
Output is correct |