Submission #1007937

# Submission time Handle Problem Language Result Execution time Memory
1007937 2024-06-26T01:10:50 Z devariaota Lasers (NOI19_lasers) C++17
100 / 100
79 ms 9136 KB
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;
const int maxq = 5e5;

int n, q;
int k, b[maxq+5];
vector<pair<int, int>> v; // list of segments that are defended no matter what

// given a base of length n (1...n)
// a laser will be shot from afar
// there are q layers of defense
// each layer of defense consist of k walls of length b[j] for 1 <= j <= k
// those walls must be placed in order of the input (i.e. the j-th wall must be placed before the j+1th wall)
// walls can not overlap

signed main() {
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  cin >> n >> q;
  for (int i=1; i<=q; i++) {
    cin >> k;
    int suff = 0, pref = 0;
    for (int j=1; j<=k; j++) {
      cin >> b[j];
      suff += b[j];
    }
    for (int j=1; j<=k; j++) {
      int l = pref+1, r = n - suff + b[j];
      int lb = r - b[j] + 1, rb = l + b[j] - 1;
      if (lb <= rb) v.push_back({lb, rb});
      pref += b[j];
      suff -= b[j];
    }
  }
  sort(v.begin(), v.end());
  int lb = 0, rb = -1, ans = 0;
  for (auto i: v) {
    if (rb < i.fi) {
      ans += rb - lb + 1;
      lb = i.fi;
      rb = i.se;
      continue;
    }
    rb = max(rb, i.se);
  }
  ans += rb - lb + 1;
  cout << ans << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 58 ms 9136 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 65 ms 6600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 8144 KB Output is correct
2 Correct 5 ms 3296 KB Output is correct
3 Correct 6 ms 3040 KB Output is correct
4 Correct 27 ms 8672 KB Output is correct
5 Correct 12 ms 4824 KB Output is correct
6 Correct 15 ms 4056 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 18 ms 3780 KB Output is correct
9 Correct 13 ms 7888 KB Output is correct
10 Correct 24 ms 8880 KB Output is correct
# Verdict Execution time Memory 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 8144 KB Output is correct
2 Correct 5 ms 3296 KB Output is correct
3 Correct 6 ms 3040 KB Output is correct
4 Correct 27 ms 8672 KB Output is correct
5 Correct 12 ms 4824 KB Output is correct
6 Correct 15 ms 4056 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 18 ms 3780 KB Output is correct
9 Correct 13 ms 7888 KB Output is correct
10 Correct 24 ms 8880 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 64 ms 5168 KB Output is correct
22 Correct 11 ms 1500 KB Output is correct
23 Correct 7 ms 3804 KB Output is correct
24 Correct 27 ms 8148 KB Output is correct
25 Correct 66 ms 5064 KB Output is correct
26 Correct 23 ms 5072 KB Output is correct
27 Correct 9 ms 1500 KB Output is correct
28 Correct 63 ms 5884 KB Output is correct
29 Correct 65 ms 5844 KB Output is correct
30 Correct 25 ms 4824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 58 ms 9136 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 65 ms 6600 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 24 ms 8144 KB Output is correct
22 Correct 5 ms 3296 KB Output is correct
23 Correct 6 ms 3040 KB Output is correct
24 Correct 27 ms 8672 KB Output is correct
25 Correct 12 ms 4824 KB Output is correct
26 Correct 15 ms 4056 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 18 ms 3780 KB Output is correct
29 Correct 13 ms 7888 KB Output is correct
30 Correct 24 ms 8880 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 64 ms 5168 KB Output is correct
42 Correct 11 ms 1500 KB Output is correct
43 Correct 7 ms 3804 KB Output is correct
44 Correct 27 ms 8148 KB Output is correct
45 Correct 66 ms 5064 KB Output is correct
46 Correct 23 ms 5072 KB Output is correct
47 Correct 9 ms 1500 KB Output is correct
48 Correct 63 ms 5884 KB Output is correct
49 Correct 65 ms 5844 KB Output is correct
50 Correct 25 ms 4824 KB Output is correct
51 Correct 10 ms 3796 KB Output is correct
52 Correct 67 ms 6532 KB Output is correct
53 Correct 79 ms 5324 KB Output is correct
54 Correct 17 ms 2516 KB Output is correct
55 Correct 39 ms 4820 KB Output is correct
56 Correct 24 ms 7124 KB Output is correct
57 Correct 26 ms 5076 KB Output is correct
58 Correct 68 ms 6436 KB Output is correct
59 Correct 20 ms 2516 KB Output is correct
60 Correct 27 ms 2668 KB Output is correct