#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll MOD=1e9+7;
using namespace std;
ll N,M,s[500005];
map <pair<ll,ll>,ll> a;
map <pair<ll,ll>,ll> pref;
map <pair<ll,ll>,ll> suff;
vector <pair<ll,ll> > vec;
int main(){
cin>>N>>M;
for(int i=1;i<=M;i++){
cin>>s[i];
for(int j=1;j<=s[i];j++){
ll y;
cin>>y;
a[{i,j}]=y;
}
pref[{i,0}]=0;
suff[{i,s[i]+1}]=0;
for(int j=1;j<=s[i];j++){
pref[{i,j}]=pref[{i,j-1}]+a[{i,j}];
}
for(int j=s[i];j>=1;j--){
suff[{i,j}]=suff[{i,j+1}]+a[{i,j}];
}
for(int j=1;j<=s[i];j++){
ll l=N-suff[{i,j}]+1;
ll r=pref[{i,j}];
if(l<=r){
vec.push_back({l,r});
}
}
}
sort(vec.begin(),vec.end());
if(vec.empty()){
cout<<0<<endl;
return 0;
}
ll l=vec[0].fi;
ll r=vec[0].se;
ll ans=r-l+1;
for(int i=1;i<vec.size();i++){
if(vec[i].fi>r){
l=vec[i].fi;
r=vec[i].se;
ans+=vec[i].se-vec[i].fi+1;
}
else if(vec[i].se>r){
l=vec[i].fi;
r=vec[i].se;
ans+=vec[i].se-r;
}
}
cout<<ans<<endl;
}
Compilation message
lasers.cpp: In function 'int main()':
lasers.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=1;i<vec.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Execution timed out |
1096 ms |
170724 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
509 ms |
61924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
509 ms |
61924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 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 |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Execution timed out |
1096 ms |
170724 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |