Submission #950417

# Submission time Handle Problem Language Result Execution time Memory
950417 2024-03-20T09:36:31 Z arbuzick Cell Automaton (JOI23_cell) C++17
24 / 100
8000 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;
        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;
                    it--;
                    int l = it->first;
                    segms.erase(segms.lower_bound(make_pair(l, -1)));
                    segms.erase(segms.lower_bound(make_pair(ind + 1, -1)));
                    segms.emplace(l, r);
                    cntp++;
                } else {
                    cntp--;
                }
            } else {
                if (t == 0) {
                    ans[t] = n;
                } else {
                    for (auto [l, r] : segms) {
                        ans[t] += (xy[r - 1].first - xy[l].first + 1 + t) * 1LL * 2 + (t - 1) * 1LL * 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 516 KB Output is correct
3 Correct 14 ms 348 KB Output is correct
4 Correct 16 ms 604 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 344 KB Output is correct
8 Correct 14 ms 1880 KB Output is correct
9 Correct 16 ms 604 KB Output is correct
10 Correct 17 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 19 ms 860 KB Output is correct
14 Correct 18 ms 1128 KB Output is correct
15 Correct 18 ms 856 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 424 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 488 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 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 516 KB Output is correct
3 Correct 14 ms 348 KB Output is correct
4 Correct 16 ms 604 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 344 KB Output is correct
8 Correct 14 ms 1880 KB Output is correct
9 Correct 16 ms 604 KB Output is correct
10 Correct 17 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 19 ms 860 KB Output is correct
14 Correct 18 ms 1128 KB Output is correct
15 Correct 18 ms 856 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 424 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 488 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1004 ms 1368 KB Output is correct
30 Correct 1643 ms 1504 KB Output is correct
31 Correct 2602 ms 1732 KB Output is correct
32 Correct 4618 ms 57288 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 254 ms 744 KB Output is correct
37 Correct 235 ms 588 KB Output is correct
38 Correct 3982 ms 7764 KB Output is correct
39 Correct 4314 ms 23124 KB Output is correct
40 Correct 4512 ms 65476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 14040 KB Output is correct
2 Correct 115 ms 13228 KB Output is correct
3 Correct 129 ms 14160 KB Output is correct
4 Correct 116 ms 13224 KB Output is correct
5 Correct 117 ms 13252 KB Output is correct
6 Correct 121 ms 13760 KB Output is correct
7 Correct 115 ms 13252 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 123 ms 13300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 14040 KB Output is correct
2 Correct 115 ms 13228 KB Output is correct
3 Correct 129 ms 14160 KB Output is correct
4 Correct 116 ms 13224 KB Output is correct
5 Correct 117 ms 13252 KB Output is correct
6 Correct 121 ms 13760 KB Output is correct
7 Correct 115 ms 13252 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 123 ms 13300 KB Output is correct
12 Execution timed out 8086 ms 31408 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1273 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1273 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 516 KB Output is correct
3 Correct 14 ms 348 KB Output is correct
4 Correct 16 ms 604 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 344 KB Output is correct
8 Correct 14 ms 1880 KB Output is correct
9 Correct 16 ms 604 KB Output is correct
10 Correct 17 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 19 ms 860 KB Output is correct
14 Correct 18 ms 1128 KB Output is correct
15 Correct 18 ms 856 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 424 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 488 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1004 ms 1368 KB Output is correct
30 Correct 1643 ms 1504 KB Output is correct
31 Correct 2602 ms 1732 KB Output is correct
32 Correct 4618 ms 57288 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 254 ms 744 KB Output is correct
37 Correct 235 ms 588 KB Output is correct
38 Correct 3982 ms 7764 KB Output is correct
39 Correct 4314 ms 23124 KB Output is correct
40 Correct 4512 ms 65476 KB Output is correct
41 Correct 119 ms 14040 KB Output is correct
42 Correct 115 ms 13228 KB Output is correct
43 Correct 129 ms 14160 KB Output is correct
44 Correct 116 ms 13224 KB Output is correct
45 Correct 117 ms 13252 KB Output is correct
46 Correct 121 ms 13760 KB Output is correct
47 Correct 115 ms 13252 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 452 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 123 ms 13300 KB Output is correct
52 Execution timed out 8086 ms 31408 KB Time limit exceeded
53 Halted 0 ms 0 KB -