Submission #950421

# Submission time Handle Problem Language Result Execution time Memory
950421 2024-03-20T09:40:00 Z arbuzick Cell Automaton (JOI23_cell) C++17
32 / 100
4514 ms 2097152 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<pair<int, int>> xy(n);
    bool check = true;
    for (int i = 0; i < n; ++i) {
        cin >> xy[i].first >> xy[i].second;
        if (xy[i].first != xy[i].second) {
            check = false;
        }
    }
    vector<int> t(q);
    for (int i = 0; i < q; ++i) {
        cin >> t[i];
    }
    if (!check) {
        vector<int> ans(t[q - 1] + 1);
        ans[0] = xy.size();
        set<pair<int, int>> black, gray;
        for (int i = 0; i < n; ++i) {
            black.insert(xy[i]);
        }
        for (int i = 1; i <= t[q - 1]; ++i) {
            set<pair<int, int>> black_nw;
            for (auto [x, y] : black) {
                if (!black.count({x + 1, y}) && !gray.count({x + 1, y})) {
                    black_nw.emplace(x + 1, y);
                }
                if (!black.count({x - 1, y}) && !gray.count({x - 1, y})) {
                    black_nw.emplace(x - 1, y);
                }
                if (!black.count({x, y + 1}) && !gray.count({x, y + 1})) {
                    black_nw.emplace(x, y + 1);
                }
                if (!black.count({x, y - 1}) && !gray.count({x, y - 1})) {
                    black_nw.emplace(x, y - 1);
                }
            }
            gray = black;
            black = black_nw;
            ans[i] = black.size();
        }
        for (int i = 0; i < q; ++i) {
            cout << ans[t[i]] << '\n';
        }
    } else {
        sort(xy.begin(), xy.end());
        vector<pair<int, int>> tms;
        for (int i = 0; i < q; ++i) {
            tms.emplace_back(t[i], n);
        }
        for (int i = 0; i + 1 < n; ++i) {
            tms.emplace_back(xy[i + 1].first - xy[i].first, i);
            tms.emplace_back(xy[i + 1].first - xy[i].first + 1, i);
        }
        sort(tms.begin(), tms.end());
        map<int, long long> ans;
        set<pair<int, int>> segms;
        for (int i = 0; i < n; ++i) {
            segms.emplace(i, i + 1);
        }
        int cntp = 0;
        long long sum_segms = 0;
        for (auto [t, ind] : tms) {
            if (ind < n) {
                if (t == xy[ind + 1].first - xy[ind].first) {
                    auto it = segms.lower_bound(make_pair(ind + 1, -1));
                    int r = it->second;
                    sum_segms -= xy[it->second - 1].first - xy[it->first].first;
                    it--;
                    int l = it->first;
                    sum_segms -= xy[it->second - 1].first - xy[it->first].first;
                    segms.erase(segms.lower_bound(make_pair(l, -1)));
                    segms.erase(segms.lower_bound(make_pair(ind + 1, -1)));
                    segms.emplace(l, r);
                    sum_segms += xy[r - 1].first - xy[l].first;
                    cntp++;
                } else {
                    cntp--;
                }
            } else {
                ans[t] = 0;
                if (t == 0) {
                    ans[t] = n;
                } else {
                    ans[t] += sum_segms * 2;
                    ans[t] += segms.size() * 1LL * (t + 1) * 2;
                    ans[t] += segms.size() * 1LL * (t - 1) * 2;
                    ans[t] += cntp * 1LL * (t - 1);
                }
            }
        }
        for (int i = 0; i < q; ++i) {
            cout << ans[t[i]] << '\n';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 13 ms 348 KB Output is correct
4 Correct 16 ms 640 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 15 ms 1840 KB Output is correct
9 Correct 15 ms 604 KB Output is correct
10 Correct 15 ms 604 KB Output is correct
11 Correct 15 ms 600 KB Output is correct
12 Correct 18 ms 1116 KB Output is correct
13 Correct 18 ms 860 KB Output is correct
14 Correct 18 ms 1132 KB Output is correct
15 Correct 19 ms 1116 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 480 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 3 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 13 ms 348 KB Output is correct
4 Correct 16 ms 640 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 15 ms 1840 KB Output is correct
9 Correct 15 ms 604 KB Output is correct
10 Correct 15 ms 604 KB Output is correct
11 Correct 15 ms 600 KB Output is correct
12 Correct 18 ms 1116 KB Output is correct
13 Correct 18 ms 860 KB Output is correct
14 Correct 18 ms 1132 KB Output is correct
15 Correct 19 ms 1116 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 480 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 3 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1012 ms 1456 KB Output is correct
30 Correct 1645 ms 1628 KB Output is correct
31 Correct 2588 ms 1948 KB Output is correct
32 Correct 4514 ms 57172 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 233 ms 608 KB Output is correct
37 Correct 242 ms 1048 KB Output is correct
38 Correct 4022 ms 7612 KB Output is correct
39 Correct 4301 ms 23204 KB Output is correct
40 Correct 4446 ms 65668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 13512 KB Output is correct
2 Correct 117 ms 13216 KB Output is correct
3 Correct 114 ms 13248 KB Output is correct
4 Correct 127 ms 13392 KB Output is correct
5 Correct 115 ms 14020 KB Output is correct
6 Correct 125 ms 13884 KB Output is correct
7 Correct 136 ms 13884 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 115 ms 13460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 13512 KB Output is correct
2 Correct 117 ms 13216 KB Output is correct
3 Correct 114 ms 13248 KB Output is correct
4 Correct 127 ms 13392 KB Output is correct
5 Correct 115 ms 14020 KB Output is correct
6 Correct 125 ms 13884 KB Output is correct
7 Correct 136 ms 13884 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 115 ms 13460 KB Output is correct
12 Correct 610 ms 60392 KB Output is correct
13 Correct 675 ms 60704 KB Output is correct
14 Correct 562 ms 61620 KB Output is correct
15 Correct 565 ms 62228 KB Output is correct
16 Correct 475 ms 50540 KB Output is correct
17 Correct 552 ms 50360 KB Output is correct
18 Correct 468 ms 53852 KB Output is correct
19 Correct 554 ms 61060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1463 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1463 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 6 ms 348 KB Output is correct
3 Correct 13 ms 348 KB Output is correct
4 Correct 16 ms 640 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 15 ms 1840 KB Output is correct
9 Correct 15 ms 604 KB Output is correct
10 Correct 15 ms 604 KB Output is correct
11 Correct 15 ms 600 KB Output is correct
12 Correct 18 ms 1116 KB Output is correct
13 Correct 18 ms 860 KB Output is correct
14 Correct 18 ms 1132 KB Output is correct
15 Correct 19 ms 1116 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 480 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 2 ms 344 KB Output is correct
22 Correct 3 ms 452 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1012 ms 1456 KB Output is correct
30 Correct 1645 ms 1628 KB Output is correct
31 Correct 2588 ms 1948 KB Output is correct
32 Correct 4514 ms 57172 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 233 ms 608 KB Output is correct
37 Correct 242 ms 1048 KB Output is correct
38 Correct 4022 ms 7612 KB Output is correct
39 Correct 4301 ms 23204 KB Output is correct
40 Correct 4446 ms 65668 KB Output is correct
41 Correct 115 ms 13512 KB Output is correct
42 Correct 117 ms 13216 KB Output is correct
43 Correct 114 ms 13248 KB Output is correct
44 Correct 127 ms 13392 KB Output is correct
45 Correct 115 ms 14020 KB Output is correct
46 Correct 125 ms 13884 KB Output is correct
47 Correct 136 ms 13884 KB Output is correct
48 Correct 0 ms 344 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 115 ms 13460 KB Output is correct
52 Correct 610 ms 60392 KB Output is correct
53 Correct 675 ms 60704 KB Output is correct
54 Correct 562 ms 61620 KB Output is correct
55 Correct 565 ms 62228 KB Output is correct
56 Correct 475 ms 50540 KB Output is correct
57 Correct 552 ms 50360 KB Output is correct
58 Correct 468 ms 53852 KB Output is correct
59 Correct 554 ms 61060 KB Output is correct
60 Runtime error 1463 ms 2097152 KB Execution killed with signal 9
61 Halted 0 ms 0 KB -