Submission #410119

# Submission time Handle Problem Language Result Execution time Memory
410119 2021-05-22T03:49:36 Z jhwest2 IOI Fever (JOI21_fever) C++14
6 / 100
2 ms 336 KB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
const int MAX = 1e5 + 10;

int n;
pint A[MAX];
set<pair<pint, int>> X[4], Y[4], Z[4], W[4];

int get_dir(int x) {
    if (x == 1) return 2;
    int a = (A[x].vb - A[x].va >= A[1].vb - A[1].va);
    int b = (A[x].vb + A[x].va <= A[1].vb + A[1].va);
    if (!a && b) return 3;
    return a + b;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> A[i].va >> A[i].vb, A[i].va *= 2, A[i].vb *= 2;
    for (int i = n; i >= 1; i--) A[i].va -= A[1].va, A[i].vb -= A[1].vb;
    int ans = 0;
    for (int d = 0; d < 4; d++) {
        int k = 0;
        for (int i = 2; i <= n; i++) {
            X[get_dir(i)].insert({ {A[i].vb, A[i].va}, i });
            Y[get_dir(i)].insert({ {A[i].va, A[i].vb}, i });
            Z[get_dir(i)].insert({ {A[i].va - A[i].vb, A[i].va}, i });
            W[get_dir(i)].insert({ {A[i].va + A[i].vb, A[i].va}, i });
        }

        vector<pint> V; V.emplace_back(0, 1);
        while (!V.empty()) {
            int x = V.back().vb, r = V.back().va; V.pop_back();
            int dir = get_dir(x); ++k;

            pair<pint, int> a, b, c;
            if (dir & 1) a = { {A[x].va, A[x].vb + (2 - (dir + 2) % 4) * r}, 0 };
            else a = { {A[x].vb, A[x].va + (1 - (dir + 2) % 4) * r}, 0 };
            b = { {A[x].va - A[x].vb, A[x].va + (1 - (dir + 2) % 4 / 2 * 2) * r}, 0 };
            c = { {A[x].va + A[x].vb, A[x].va + (1 - (1 + (dir + 2) % 4) % 4 / 2) * r}, 0 };

            vector<int> Upd;
            if (dir == 2) {
                for (auto it = X[0].lower_bound(a); it != X[0].end() && it->va.va == A[x].vb; it = next(it)) Upd.push_back(it->vb);
            }
            if (dir == 3) {
                for (auto it = Y[1].lower_bound(a); it != Y[1].end() && it->va.va == A[x].va; it = next(it)) Upd.push_back(it->vb);
            }
            if (dir == 0) {
                for (auto it = X[2].lower_bound(a); it != X[2].begin() && prev(it)->va.va == A[x].vb; it = prev(it)) Upd.push_back(prev(it)->vb);
            }
            if (dir == 1) {
                for (auto it = Y[3].lower_bound(a); it != Y[3].begin() && prev(it)->va.va == A[x].va; it = prev(it)) Upd.push_back(prev(it)->vb);
            }

            if (dir > 1) {
                for (auto it = Z[(7 - dir) % 4].lower_bound(b); it != Z[(7 - dir) % 4].end() && it->va.va == A[x].va - A[x].vb; it = next(it)) Upd.push_back(it->vb);
            }
            else {
                for (auto it = Z[(7 - dir) % 4].lower_bound(b); it != Z[(7 - dir) % 4].begin() && prev(it)->va.va == A[x].va - A[x].vb; it = prev(it)) Upd.push_back(prev(it)->vb);
            }
            if ((1 + dir) % 4 > 1) {
                for (auto it = W[(5 - dir) % 4].lower_bound(c); it != W[(5 - dir) % 4].end() && it->va.va == A[x].va + A[x].vb; it = next(it)) Upd.push_back(it->vb);
            }
            else {
                for (auto it = W[(5 - dir) % 4].lower_bound(c); it != W[(5 - dir) % 4].begin() && prev(it)->va.va == A[x].va + A[x].vb; it = prev(it)) Upd.push_back(prev(it)->vb);
            }

            for (int k : Upd) {
                int z = A[k].va, y = A[k].vb;
                for (int i = 0; i < 4; i++) {
                    X[i].erase({ {y, z}, k });
                    Y[i].erase({ {z, y}, k });
                    Z[i].erase({ {z - y, z}, k });
                    W[i].erase({ {z + y, z}, k });
                }
                if (A[x].va == A[k].va) V.emplace_back(abs(A[k].vb - A[x].vb) / 2, k);
                else if (A[x].vb == A[k].vb) V.emplace_back(abs(A[k].va - A[x].va) / 2, k);
                else V.emplace_back(abs(A[k].va - A[x].va), k);
            }
        }
        ans = max(ans, k);
        for (int i = 1; i <= n; i++) {
            swap(A[i].va, A[i].vb); A[i].va = -A[i].va;
        }
        for (int i = 0; i < 4; i++) {
            X[i].clear(); Y[i].clear(); Z[i].clear(); W[i].clear();
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 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 328 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 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 328 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 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 328 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 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 328 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 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 328 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 328 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 328 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Incorrect 1 ms 204 KB Output isn't correct