답안 #643015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643015 2022-09-21T04:26:07 Z devariaota Lasers (NOI19_lasers) C++17
100 / 100
301 ms 13940 KB
#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];
vector <pair<ll,ll> > vec;
int main(){
  cin>>N>>M;
  for(int i=1;i<=M;i++){
    cin>>s[i];
    ll a[s[i]+2];
    ll pref[s[i]+2];
    ll suff[s[i]+2];
    for(int j=1;j<=s[i];j++){
      ll y;
      cin>>y;
      a[j]=y;
    }
    pref[0]=0;
    suff[s[i]+1]=0;
    for(int j=1;j<=s[i];j++){
      pref[j]=pref[j-1]+a[j];
    }
    for(int j=s[i];j>=1;j--){
      suff[j]=suff[j+1]+a[j];
    }
    for(int j=1;j<=s[i];j++){
      ll l=N-suff[j]+1;
      ll r=pref[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){
      ans+=vec[i].se-vec[i].fi+1;
      l=vec[i].fi;
      r=vec[i].se;
    }
    else if(vec[i].se>r){
      ans+=vec[i].se-r;
      l=vec[i].fi;
      r=vec[i].se;
    }
  }
  cout<<ans<<endl;
}
/*
20 6
1 8
2 2 8
3 2 2 8
4 2 2 2 8
5 2 2 2 2 8
6 2 2 2 2 2 8
*/

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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 301 ms 11852 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 272 ms 7588 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 8248 KB Output is correct
2 Correct 13 ms 2492 KB Output is correct
3 Correct 18 ms 2124 KB Output is correct
4 Correct 61 ms 9168 KB Output is correct
5 Correct 27 ms 5832 KB Output is correct
6 Correct 58 ms 10108 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 67 ms 8504 KB Output is correct
9 Correct 39 ms 7204 KB Output is correct
10 Correct 63 ms 9748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 8248 KB Output is correct
2 Correct 13 ms 2492 KB Output is correct
3 Correct 18 ms 2124 KB Output is correct
4 Correct 61 ms 9168 KB Output is correct
5 Correct 27 ms 5832 KB Output is correct
6 Correct 58 ms 10108 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 67 ms 8504 KB Output is correct
9 Correct 39 ms 7204 KB Output is correct
10 Correct 63 ms 9748 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 229 ms 12484 KB Output is correct
22 Correct 34 ms 1984 KB Output is correct
23 Correct 21 ms 2344 KB Output is correct
24 Correct 105 ms 7744 KB Output is correct
25 Correct 231 ms 12472 KB Output is correct
26 Correct 67 ms 5772 KB Output is correct
27 Correct 28 ms 1880 KB Output is correct
28 Correct 244 ms 12440 KB Output is correct
29 Correct 249 ms 12436 KB Output is correct
30 Correct 59 ms 4832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 301 ms 11852 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 272 ms 7588 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 59 ms 8248 KB Output is correct
22 Correct 13 ms 2492 KB Output is correct
23 Correct 18 ms 2124 KB Output is correct
24 Correct 61 ms 9168 KB Output is correct
25 Correct 27 ms 5832 KB Output is correct
26 Correct 58 ms 10108 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 67 ms 8504 KB Output is correct
29 Correct 39 ms 7204 KB Output is correct
30 Correct 63 ms 9748 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 304 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 316 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 229 ms 12484 KB Output is correct
42 Correct 34 ms 1984 KB Output is correct
43 Correct 21 ms 2344 KB Output is correct
44 Correct 105 ms 7744 KB Output is correct
45 Correct 231 ms 12472 KB Output is correct
46 Correct 67 ms 5772 KB Output is correct
47 Correct 28 ms 1880 KB Output is correct
48 Correct 244 ms 12440 KB Output is correct
49 Correct 249 ms 12436 KB Output is correct
50 Correct 59 ms 4832 KB Output is correct
51 Correct 33 ms 2728 KB Output is correct
52 Correct 271 ms 13628 KB Output is correct
53 Correct 271 ms 13652 KB Output is correct
54 Correct 62 ms 3888 KB Output is correct
55 Correct 152 ms 6920 KB Output is correct
56 Correct 85 ms 7760 KB Output is correct
57 Correct 94 ms 6532 KB Output is correct
58 Correct 272 ms 13940 KB Output is correct
59 Correct 66 ms 3492 KB Output is correct
60 Correct 99 ms 4664 KB Output is correct