Submission #224619

#TimeUsernameProblemLanguageResultExecution timeMemory
224619NightlightLasers (NOI19_lasers)C++14
100 / 100
192 ms10024 KiB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define l first
#define r second
using namespace std;

int L, N, M;
int pos[500005];
pii ran[500005];
int ans;

int main() {
//  freopen("inp", "r", stdin);
  scanf("%d %d", &L, &N);
  int l, r, p = 0;
  for(int i = 1; i <= N; i++) {
    scanf("%d", &M);
    for(int j = 1; j <= M; j++) {
      scanf("%d", &pos[j]);
      pos[j] += pos[j - 1];
    }
    for(int j = 1; j <= M; j++) {
      l = L - (pos[M] - pos[j - 1]) + 1, r = pos[j];
      if(l <= r) {
        ran[++p] = {l, r};
      }
    }
  }
  sort(ran + 1, ran + p + 1);
  int ln = 0, rn = -1;
  for(int i = 1; i <= p; i++) {
    if(ran[i].l > rn) {
      ans += rn - ln + 1;
      ln = ran[i].l;
      rn = ran[i].r;
    }else {
      rn = max(ran[i].r, rn);
    }
  }
  ans += rn - ln + 1;
  printf("%d\n", ans);
}

Compilation message (stderr)

lasers.cpp: In function 'int main()':
lasers.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &L, &N);
   ~~~~~^~~~~~~~~~~~~~~~~
lasers.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &M);
     ~~~~~^~~~~~~~~~
lasers.cpp:19:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &pos[j]);
       ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...