# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1007864 |
2024-06-25T15:41:31 Z |
devariaota |
Lasers (NOI19_lasers) |
C++17 |
|
202 ms |
46212 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define fi first
#define sec second
#define endl '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 998244353;
const ll N = 5e5 + 5;
const ll INF = 1e18;
vector<ll>vec[N];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
int tc = 1;
// cin >> tc;
while(tc--){
ll n,q; cin >> n >> q;
for(int i=1;i<=q;i++){
ll a; cin >> a;
for(int j=1;j<=a;j++){
ll x; cin >> x;
vec[i].pb(x);
}
}
set<pii>interval;
for(int i=1;i<=q;i++){
ll l = 1;
vector<ll>suff(vec[i].size() + 5);
for(int j=vec[i].size();j>=0;j--){
if(j == vec[i].size()-1) suff[j] = vec[i][j];
else suff[j] = suff[j+1] + vec[i][j];
}
for(int j=0;j<vec[i].size();j++){
ll val = max(0LL, 2*vec[i][j] - (n-(j == vec[i].size()-1 ? 0 : suff[j+1])-l+1));
if(val > 0) interval.insert({l-val+vec[i][j], l+vec[i][j]-1});
l += vec[i][j];
}
}
if(interval.size() == 0){
cout << 0 << endl;
continue;
}
ll last = -1, prev = -1, mx = 0, ans = 0;
for(auto i : interval){
if(prev == -1) prev = i.fi;
if(i.fi != prev){
ans += max(0LL, last - max(prev - 1,mx));
mx = max(mx, last);
prev = i.fi;
last = 0;
}
last = i.sec;
}
ans += max(0LL, last - max(prev - 1,mx));
cout << ans << endl;
}
}
/*
1 2 3 4 5 6 7 8 9 10 11
*/
Compilation message
lasers.cpp: In function 'int32_t main()':
lasers.cpp:39:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(j == vec[i].size()-1) suff[j] = vec[i][j];
| ~~^~~~~~~~~~~~~~~~~~
lasers.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j=0;j<vec[i].size();j++){
| ~^~~~~~~~~~~~~~
lasers.cpp:43:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | ll val = max(0LL, 2*vec[i][j] - (n-(j == vec[i].size()-1 ? 0 : suff[j+1])-l+1));
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
2 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
4 ms |
12132 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
2 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
2 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
4 ms |
12132 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
2 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
11 |
Correct |
4 ms |
12124 KB |
Output is correct |
12 |
Correct |
75 ms |
27288 KB |
Output is correct |
13 |
Correct |
4 ms |
12196 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12124 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
202 ms |
40608 KB |
Output is correct |
18 |
Correct |
3 ms |
12124 KB |
Output is correct |
19 |
Correct |
3 ms |
12124 KB |
Output is correct |
20 |
Correct |
2 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
26232 KB |
Output is correct |
2 |
Correct |
11 ms |
14576 KB |
Output is correct |
3 |
Correct |
8 ms |
14280 KB |
Output is correct |
4 |
Correct |
44 ms |
27408 KB |
Output is correct |
5 |
Correct |
19 ms |
18632 KB |
Output is correct |
6 |
Correct |
29 ms |
18964 KB |
Output is correct |
7 |
Correct |
4 ms |
12380 KB |
Output is correct |
8 |
Correct |
31 ms |
24636 KB |
Output is correct |
9 |
Correct |
30 ms |
22588 KB |
Output is correct |
10 |
Correct |
50 ms |
30396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12120 KB |
Output is correct |
2 |
Correct |
2 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12200 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
2 ms |
12124 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
2 ms |
12124 KB |
Output is correct |
10 |
Correct |
2 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
26232 KB |
Output is correct |
2 |
Correct |
11 ms |
14576 KB |
Output is correct |
3 |
Correct |
8 ms |
14280 KB |
Output is correct |
4 |
Correct |
44 ms |
27408 KB |
Output is correct |
5 |
Correct |
19 ms |
18632 KB |
Output is correct |
6 |
Correct |
29 ms |
18964 KB |
Output is correct |
7 |
Correct |
4 ms |
12380 KB |
Output is correct |
8 |
Correct |
31 ms |
24636 KB |
Output is correct |
9 |
Correct |
30 ms |
22588 KB |
Output is correct |
10 |
Correct |
50 ms |
30396 KB |
Output is correct |
11 |
Correct |
4 ms |
12120 KB |
Output is correct |
12 |
Correct |
2 ms |
12124 KB |
Output is correct |
13 |
Correct |
3 ms |
12124 KB |
Output is correct |
14 |
Correct |
3 ms |
12124 KB |
Output is correct |
15 |
Correct |
2 ms |
12200 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
2 ms |
12124 KB |
Output is correct |
18 |
Correct |
3 ms |
12124 KB |
Output is correct |
19 |
Correct |
2 ms |
12124 KB |
Output is correct |
20 |
Correct |
2 ms |
12124 KB |
Output is correct |
21 |
Correct |
152 ms |
40384 KB |
Output is correct |
22 |
Correct |
27 ms |
17748 KB |
Output is correct |
23 |
Correct |
14 ms |
16232 KB |
Output is correct |
24 |
Correct |
56 ms |
27492 KB |
Output is correct |
25 |
Correct |
167 ms |
40528 KB |
Output is correct |
26 |
Correct |
56 ms |
23884 KB |
Output is correct |
27 |
Correct |
24 ms |
16980 KB |
Output is correct |
28 |
Correct |
143 ms |
40308 KB |
Output is correct |
29 |
Correct |
192 ms |
40800 KB |
Output is correct |
30 |
Correct |
33 ms |
23176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12120 KB |
Output is correct |
2 |
Correct |
2 ms |
12124 KB |
Output is correct |
3 |
Correct |
3 ms |
12124 KB |
Output is correct |
4 |
Correct |
3 ms |
12124 KB |
Output is correct |
5 |
Correct |
2 ms |
12124 KB |
Output is correct |
6 |
Correct |
3 ms |
12124 KB |
Output is correct |
7 |
Correct |
4 ms |
12132 KB |
Output is correct |
8 |
Correct |
3 ms |
12124 KB |
Output is correct |
9 |
Correct |
2 ms |
12124 KB |
Output is correct |
10 |
Correct |
3 ms |
12124 KB |
Output is correct |
11 |
Correct |
4 ms |
12124 KB |
Output is correct |
12 |
Correct |
75 ms |
27288 KB |
Output is correct |
13 |
Correct |
4 ms |
12196 KB |
Output is correct |
14 |
Correct |
2 ms |
12124 KB |
Output is correct |
15 |
Correct |
3 ms |
12124 KB |
Output is correct |
16 |
Correct |
3 ms |
12124 KB |
Output is correct |
17 |
Correct |
202 ms |
40608 KB |
Output is correct |
18 |
Correct |
3 ms |
12124 KB |
Output is correct |
19 |
Correct |
3 ms |
12124 KB |
Output is correct |
20 |
Correct |
2 ms |
12124 KB |
Output is correct |
21 |
Correct |
41 ms |
26232 KB |
Output is correct |
22 |
Correct |
11 ms |
14576 KB |
Output is correct |
23 |
Correct |
8 ms |
14280 KB |
Output is correct |
24 |
Correct |
44 ms |
27408 KB |
Output is correct |
25 |
Correct |
19 ms |
18632 KB |
Output is correct |
26 |
Correct |
29 ms |
18964 KB |
Output is correct |
27 |
Correct |
4 ms |
12380 KB |
Output is correct |
28 |
Correct |
31 ms |
24636 KB |
Output is correct |
29 |
Correct |
30 ms |
22588 KB |
Output is correct |
30 |
Correct |
50 ms |
30396 KB |
Output is correct |
31 |
Correct |
4 ms |
12120 KB |
Output is correct |
32 |
Correct |
2 ms |
12124 KB |
Output is correct |
33 |
Correct |
3 ms |
12124 KB |
Output is correct |
34 |
Correct |
3 ms |
12124 KB |
Output is correct |
35 |
Correct |
2 ms |
12200 KB |
Output is correct |
36 |
Correct |
3 ms |
12124 KB |
Output is correct |
37 |
Correct |
2 ms |
12124 KB |
Output is correct |
38 |
Correct |
3 ms |
12124 KB |
Output is correct |
39 |
Correct |
2 ms |
12124 KB |
Output is correct |
40 |
Correct |
2 ms |
12124 KB |
Output is correct |
41 |
Correct |
152 ms |
40384 KB |
Output is correct |
42 |
Correct |
27 ms |
17748 KB |
Output is correct |
43 |
Correct |
14 ms |
16232 KB |
Output is correct |
44 |
Correct |
56 ms |
27492 KB |
Output is correct |
45 |
Correct |
167 ms |
40528 KB |
Output is correct |
46 |
Correct |
56 ms |
23884 KB |
Output is correct |
47 |
Correct |
24 ms |
16980 KB |
Output is correct |
48 |
Correct |
143 ms |
40308 KB |
Output is correct |
49 |
Correct |
192 ms |
40800 KB |
Output is correct |
50 |
Correct |
33 ms |
23176 KB |
Output is correct |
51 |
Correct |
18 ms |
17820 KB |
Output is correct |
52 |
Correct |
164 ms |
44636 KB |
Output is correct |
53 |
Correct |
159 ms |
43620 KB |
Output is correct |
54 |
Correct |
39 ms |
20052 KB |
Output is correct |
55 |
Correct |
90 ms |
30008 KB |
Output is correct |
56 |
Correct |
72 ms |
25392 KB |
Output is correct |
57 |
Correct |
64 ms |
25032 KB |
Output is correct |
58 |
Correct |
188 ms |
46212 KB |
Output is correct |
59 |
Correct |
44 ms |
21956 KB |
Output is correct |
60 |
Correct |
56 ms |
24112 KB |
Output is correct |