Submission #816591

# Submission time Handle Problem Language Result Execution time Memory
816591 2023-08-09T05:48:27 Z gun_gan Lasers (NOI19_lasers) C++17
100 / 100
205 ms 15272 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX = 5e5 + 5;
int R, L;

vector<pair<int,int>> vv;

int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      cin >> L >> R;
      for(int i = 0; i < R; i++) {
            int x;
            cin >> x;

            vector<int> v;
            vector<pair<int,int>> ranges;

            int sum = 0;
            for(int j = 0; j < x; j++) {
                  int k;
                  cin >> k;
                  v.push_back(k);
                  sum += k;
            }

            int l = 1, r = L - sum; // ga ke cover

            ranges.push_back({l, r});

            for(int j = 0; j < x; j++) {
                  l += v[j];
                  r += v[j];

                  ranges.push_back({l, r});
            }

            sort(ranges.begin(), ranges.end());

            set<int> open;
            int lst = 0;
            for(auto [l, r] : ranges) {
                  while(!open.empty() && *open.begin() < l) {
                        open.erase(open.begin());
                  }

                  if(open.empty()) {
                        if(l - 1 >= lst + 1) {
                              vv.push_back({lst + 1, l - 1}); // selalu ke cover
                        }
                  }

                  open.insert(r);
                  lst = r;
            }

            if(lst + 1 <= L) vv.push_back({lst + 1, L});
      }

      sort(vv.begin(), vv.end());
      set<int> open;
      
      int ans = 0, lf = 1, rg = 0;

      for(auto [l, r] : vv) {
            while(!open.empty() && *open.begin() < l) {
                  open.erase(open.begin());
            }

            if(open.empty()) {
                  ans += rg - lf + 1;
                  lf = l, rg = r;
            }

            open.insert(r);
            rg = max(rg, r);
      }

      ans += rg - lf + 1;

      cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 340 KB Output is correct
12 Correct 139 ms 5572 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 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 177 ms 13148 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 6408 KB Output is correct
2 Correct 9 ms 1616 KB Output is correct
3 Correct 12 ms 1516 KB Output is correct
4 Correct 50 ms 7272 KB Output is correct
5 Correct 22 ms 3428 KB Output is correct
6 Correct 48 ms 6688 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 53 ms 8908 KB Output is correct
9 Correct 27 ms 3964 KB Output is correct
10 Correct 54 ms 8024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 6408 KB Output is correct
2 Correct 9 ms 1616 KB Output is correct
3 Correct 12 ms 1516 KB Output is correct
4 Correct 50 ms 7272 KB Output is correct
5 Correct 22 ms 3428 KB Output is correct
6 Correct 48 ms 6688 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 53 ms 8908 KB Output is correct
9 Correct 27 ms 3964 KB Output is correct
10 Correct 54 ms 8024 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 177 ms 12628 KB Output is correct
22 Correct 26 ms 1484 KB Output is correct
23 Correct 15 ms 1700 KB Output is correct
24 Correct 63 ms 6144 KB Output is correct
25 Correct 180 ms 12620 KB Output is correct
26 Correct 52 ms 3644 KB Output is correct
27 Correct 21 ms 1352 KB Output is correct
28 Correct 177 ms 12496 KB Output is correct
29 Correct 185 ms 12624 KB Output is correct
30 Correct 48 ms 3880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 340 KB Output is correct
12 Correct 139 ms 5572 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 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 177 ms 13148 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 52 ms 6408 KB Output is correct
22 Correct 9 ms 1616 KB Output is correct
23 Correct 12 ms 1516 KB Output is correct
24 Correct 50 ms 7272 KB Output is correct
25 Correct 22 ms 3428 KB Output is correct
26 Correct 48 ms 6688 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 53 ms 8908 KB Output is correct
29 Correct 27 ms 3964 KB Output is correct
30 Correct 54 ms 8024 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 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 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 177 ms 12628 KB Output is correct
42 Correct 26 ms 1484 KB Output is correct
43 Correct 15 ms 1700 KB Output is correct
44 Correct 63 ms 6144 KB Output is correct
45 Correct 180 ms 12620 KB Output is correct
46 Correct 52 ms 3644 KB Output is correct
47 Correct 21 ms 1352 KB Output is correct
48 Correct 177 ms 12496 KB Output is correct
49 Correct 185 ms 12624 KB Output is correct
50 Correct 48 ms 3880 KB Output is correct
51 Correct 21 ms 2056 KB Output is correct
52 Correct 187 ms 14832 KB Output is correct
53 Correct 205 ms 14716 KB Output is correct
54 Correct 48 ms 2760 KB Output is correct
55 Correct 111 ms 3640 KB Output is correct
56 Correct 57 ms 5224 KB Output is correct
57 Correct 66 ms 3932 KB Output is correct
58 Correct 196 ms 15272 KB Output is correct
59 Correct 47 ms 2624 KB Output is correct
60 Correct 62 ms 2920 KB Output is correct