Submission #491191

# Submission time Handle Problem Language Result Execution time Memory
491191 2021-11-30T17:26:05 Z blue Lasers (NOI19_lasers) C++17
100 / 100
557 ms 52676 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({1, 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 << '\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 1 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 1 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 148 ms 28996 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 483 ms 49284 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 17328 KB Output is correct
2 Correct 15 ms 2928 KB Output is correct
3 Correct 17 ms 2048 KB Output is correct
4 Correct 118 ms 19432 KB Output is correct
5 Correct 41 ms 7284 KB Output is correct
6 Correct 61 ms 6716 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 69 ms 9552 KB Output is correct
9 Correct 68 ms 13516 KB Output is correct
10 Correct 123 ms 21672 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 0 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 0 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 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 17328 KB Output is correct
2 Correct 15 ms 2928 KB Output is correct
3 Correct 17 ms 2048 KB Output is correct
4 Correct 118 ms 19432 KB Output is correct
5 Correct 41 ms 7284 KB Output is correct
6 Correct 61 ms 6716 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 69 ms 9552 KB Output is correct
9 Correct 68 ms 13516 KB Output is correct
10 Correct 123 ms 21672 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 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 0 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 1 ms 332 KB Output is correct
21 Correct 554 ms 47268 KB Output is correct
22 Correct 68 ms 6580 KB Output is correct
23 Correct 31 ms 5060 KB Output is correct
24 Correct 145 ms 16648 KB Output is correct
25 Correct 515 ms 47032 KB Output is correct
26 Correct 160 ms 12612 KB Output is correct
27 Correct 57 ms 5492 KB Output is correct
28 Correct 486 ms 46916 KB Output is correct
29 Correct 527 ms 47300 KB Output is correct
30 Correct 84 ms 12128 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 1 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 148 ms 28996 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 483 ms 49284 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 102 ms 17328 KB Output is correct
22 Correct 15 ms 2928 KB Output is correct
23 Correct 17 ms 2048 KB Output is correct
24 Correct 118 ms 19432 KB Output is correct
25 Correct 41 ms 7284 KB Output is correct
26 Correct 61 ms 6716 KB Output is correct
27 Correct 2 ms 588 KB Output is correct
28 Correct 69 ms 9552 KB Output is correct
29 Correct 68 ms 13516 KB Output is correct
30 Correct 123 ms 21672 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 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 0 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 1 ms 332 KB Output is correct
41 Correct 554 ms 47268 KB Output is correct
42 Correct 68 ms 6580 KB Output is correct
43 Correct 31 ms 5060 KB Output is correct
44 Correct 145 ms 16648 KB Output is correct
45 Correct 515 ms 47032 KB Output is correct
46 Correct 160 ms 12612 KB Output is correct
47 Correct 57 ms 5492 KB Output is correct
48 Correct 486 ms 46916 KB Output is correct
49 Correct 527 ms 47300 KB Output is correct
50 Correct 84 ms 12128 KB Output is correct
51 Correct 39 ms 6860 KB Output is correct
52 Correct 557 ms 51376 KB Output is correct
53 Correct 538 ms 51688 KB Output is correct
54 Correct 82 ms 8796 KB Output is correct
55 Correct 261 ms 21136 KB Output is correct
56 Correct 106 ms 16548 KB Output is correct
57 Correct 200 ms 15364 KB Output is correct
58 Correct 549 ms 52676 KB Output is correct
59 Correct 154 ms 11764 KB Output is correct
60 Correct 168 ms 14056 KB Output is correct