Submission #491190

# Submission time Handle Problem Language Result Execution time Memory
491190 2021-11-30T17:24:20 Z blue Lasers (NOI19_lasers) C++17
100 / 100
561 ms 58244 KB
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <map>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#define sz(x) (int(x.size()))

map<int, int> delta;

void map_insert(int u, int d)
{
    if(delta.find(u) == delta.end())
        delta[u] = d;
    else
        delta[u] += d;
}

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

    int L, R;
    cin >> L >> R;

    vi S(1+R, 0);
    vvi blocks(1+R);

    // vi delta(1+L+1, 0);


    for(int r = 1; r <= R; r++)
    {
        // cerr << "\n\n\n";
        // cerr << "layer = " << r << '\n';
        int X;
        cin >> X;

        for(int x = 1; x <= X; x++)
        {
            int Z;
            cin >> Z;
            blocks[r].push_back(Z);
            S[r] += Z;
        }

        int left_sum = 0;

        deque<pii> H;

        for(int x = 0; x <= X; x++)
        {
            // cerr << left_sum << " , " << S[r] - left_sum << " : " << left_sum + 1 << ' ' << L - (S[r] - left_sum) << '\n';
            H.push_back({left_sum + 1, L - (S[r] - left_sum)});
            if(x != X)
            {
                left_sum += blocks[r][x];
            }
        }

        while(!H.empty())
        {
            while(sz(H) >= 2 && H[sz(H) - 2].second >= H[sz(H) - 1].first)
            {
                H[sz(H) - 2].second = H[sz(H) - 1].second;
                H.pop_back();
            }

            pii h = H.back();
            map_insert(h.first, +1);
            map_insert(h.second + 1, -1);
            // delta[h.first]++;
            // delta[h.second + 1]--;
            H.pop_back();
        }
    }

    int ans = 0;

    delta.insert({0, 0});
    int curr = 0;

    int prev = -1;
    for(pii d: delta)
    {
        // cerr << d.first << " : " << d.second << '\n';
        if(prev != -1 && curr < R)
        {
            ans += d.first - prev;
        }
        curr += d.second;
        prev = d.first;
    }
    // cerr << '\n';

    cout << ans-1 << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 145 ms 34752 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 468 ms 54788 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 308 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 17376 KB Output is correct
2 Correct 16 ms 2964 KB Output is correct
3 Correct 13 ms 2060 KB Output is correct
4 Correct 115 ms 19412 KB Output is correct
5 Correct 40 ms 7232 KB Output is correct
6 Correct 48 ms 6672 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 82 ms 9544 KB Output is correct
9 Correct 68 ms 13484 KB Output is correct
10 Correct 126 ms 21636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 17376 KB Output is correct
2 Correct 16 ms 2964 KB Output is correct
3 Correct 13 ms 2060 KB Output is correct
4 Correct 115 ms 19412 KB Output is correct
5 Correct 40 ms 7232 KB Output is correct
6 Correct 48 ms 6672 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 82 ms 9544 KB Output is correct
9 Correct 68 ms 13484 KB Output is correct
10 Correct 126 ms 21636 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 526 ms 47216 KB Output is correct
22 Correct 58 ms 6588 KB Output is correct
23 Correct 30 ms 5180 KB Output is correct
24 Correct 129 ms 16736 KB Output is correct
25 Correct 561 ms 47024 KB Output is correct
26 Correct 143 ms 12656 KB Output is correct
27 Correct 49 ms 5440 KB Output is correct
28 Correct 474 ms 46900 KB Output is correct
29 Correct 516 ms 47404 KB Output is correct
30 Correct 82 ms 12008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 145 ms 34752 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 468 ms 54788 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 308 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 99 ms 17376 KB Output is correct
22 Correct 16 ms 2964 KB Output is correct
23 Correct 13 ms 2060 KB Output is correct
24 Correct 115 ms 19412 KB Output is correct
25 Correct 40 ms 7232 KB Output is correct
26 Correct 48 ms 6672 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 82 ms 9544 KB Output is correct
29 Correct 68 ms 13484 KB Output is correct
30 Correct 126 ms 21636 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 0 ms 332 KB Output is correct
41 Correct 526 ms 47216 KB Output is correct
42 Correct 58 ms 6588 KB Output is correct
43 Correct 30 ms 5180 KB Output is correct
44 Correct 129 ms 16736 KB Output is correct
45 Correct 561 ms 47024 KB Output is correct
46 Correct 143 ms 12656 KB Output is correct
47 Correct 49 ms 5440 KB Output is correct
48 Correct 474 ms 46900 KB Output is correct
49 Correct 516 ms 47404 KB Output is correct
50 Correct 82 ms 12008 KB Output is correct
51 Correct 40 ms 7620 KB Output is correct
52 Correct 552 ms 57068 KB Output is correct
53 Correct 530 ms 57028 KB Output is correct
54 Correct 88 ms 10292 KB Output is correct
55 Correct 263 ms 24444 KB Output is correct
56 Correct 106 ms 18084 KB Output is correct
57 Correct 201 ms 17440 KB Output is correct
58 Correct 561 ms 58244 KB Output is correct
59 Correct 139 ms 13124 KB Output is correct
60 Correct 172 ms 16468 KB Output is correct