Submission #802061

# Submission time Handle Problem Language Result Execution time Memory
802061 2023-08-02T09:28:09 Z puppy IOI Fever (JOI21_fever) C++17
0 / 100
37 ms 59928 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#define all(v) (v).begin(), (v).end()
using namespace std;
struct Dot
{
    int x, y;
};
int N;
Dot dot[100005];
int dir[100005];
int dis[100005][8];
const int inf = 1e9;
vector<pair<int, int>> line[4][100005][4];
vector<pair<int, int>> minor[100005][8];
int id[100005][4];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> dot[i].x >> dot[i].y;
        if (i >= 2) {
            dot[i].x -= dot[1].x;
            dot[i].y -= dot[1].y;
        }
    }
    dot[1] = {0, 0};
    int ans = 0;
    for (int k = 0; k < 4; k++) {
        for (int i = 2; i <= N; i++) {
            if (dot[i].y < dot[i].x && -dot[i].x < dot[i].y) {
                dir[i] = 2;
            }
            else if (dot[i].y >= dot[i].x && dot[i].y > -dot[i].x) {
                dir[i] = 3;
            }
            else if (dot[i].y < dot[i].x && dot[i].y <= -dot[i].x) {
                dir[i] = 1;
            }
            else {
                dir[i] = 0;
            }
        }
        vector<int> cpx[4];
        for (int i = 1; i <= N; i++) {
            cpx[0].push_back(dot[i].y - dot[i].x);
            cpx[1].push_back(dot[i].x + dot[i].y);
            cpx[2].push_back(dot[i].y);
            cpx[3].push_back(dot[i].x);
        }
        for (int k = 0; k < 4; k++) {
            sort(all(cpx[k]));
            cpx[k].erase(unique(all(cpx[k])), cpx[k].end());
        }
        auto lb = [&](int k, int i)
        {
            return lower_bound(all(cpx[k]), i) - cpx[k].begin();
        };
        for (int k = 0; k < 4; k++) {
            for (int i = 0; i < (int)cpx[k].size(); i++) {
                for (int j = 0; j < 4; j++) {
                    line[k][i][j].clear();
                }
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 0; j < 8; j++) {
                minor[i][j].clear();
            }
        }
        for (int i = 1; i <= N; i++) {
            id[i][0] = lb(0, dot[i].y - dot[i].x);
            id[i][1] = lb(1, dot[i].y + dot[i].x);
            id[i][2] = lb(2, dot[i].y);
            id[i][3] = lb(3, dot[i].x);
            line[0][id[i][0]][dir[i]].push_back(make_pair(dot[i].x, i));
            line[1][id[i][1]][dir[i]].push_back(make_pair(dot[i].x, i));
            line[2][id[i][2]][dir[i]].push_back(make_pair(dot[i].x, i));
            line[3][id[i][3]][dir[i]].push_back(make_pair(dot[i].y, i));
        }
        for (int k = 0; k < 4; k++) {
            for (int i = 0; i < (int)cpx[k].size(); i++) {
                for (int j = 0; j < 4; j++) {
                    sort(all(line[k][i][j]));
                    for (int l = 0; l < (int)line[k][i][j].size() - 1; l++) {
                        if (k < 2) {
                            minor[line[k][i][j][l].second][2*k].push_back(make_pair(2 * (line[k][i][j][l+1].first - line[k][i][j][l].first), line[k][i][j][l+1].second));
                            minor[line[k][i][j][l+1].second][2*k+1].push_back(make_pair(2 * (line[k][i][j][l+1].first - line[k][i][j][l].first), line[k][i][j][l].second));
                        }
                        else {
                            minor[line[k][i][j][l].second][2*k].push_back(make_pair(line[k][i][j][l+1].first - line[k][i][j][l].first, line[k][i][j][l+1].second));
                            minor[line[k][i][j][l+1].second][2*k+1].push_back(make_pair(line[k][i][j][l+1].first - line[k][i][j][l].first, line[k][i][j][l].second));
                        }
                    }
                }
            }
        }
        fill(&dis[0][0], &dis[100004][8], inf);
        priority_queue<pair<int, pair<int, int>>> pq; pq.push(make_pair(0, make_pair(1, -1)));
        while (!pq.empty()) {
            int ver = pq.top().second.first, state = pq.top().second.second, now = -pq.top().first;
            pq.pop();
            if (state != -1) {
                for (pair<int, int> p: minor[ver][state]) {
                    int nxt = p.second, newdis = now + p.first;
                    if (dis[nxt][state] > newdis) {
                        dis[nxt][state] = newdis;
                        pq.push(make_pair(-newdis, make_pair(nxt, state)));
                    }
                }
            }
            if (dir[ver] == 0) {
                auto it = lower_bound(all(line[0][id[ver][0]][3]), make_pair(dot[ver].x + (now + 1) / 2, -1));
                if (it != line[0][id[ver][0]][3].end() && dis[(*it).second][0] > 2 * ((*it).first - dot[ver].x)) {
                    dis[(*it).second][0] = 2 * ((*it).first - dot[ver].x);
                    pq.push(make_pair(-dis[(*it).second][0], make_pair((*it).second, 0)));
                }
                auto it2 = lower_bound(all(line[1][id[ver][1]][1]), make_pair(dot[ver].x + (now + 1) / 2, -1));
                if (it2 != line[1][id[ver][1]][1].end() && dis[(*it2).second][2] > 2 * ((*it2).first - dot[ver].x)) {
                    dis[(*it2).second][2] = 2 * ((*it2).first - dot[ver].x);
                    pq.push(make_pair(-dis[(*it2).second][2], make_pair((*it2).second, 2)));
                }
                auto it3 = lower_bound(all(line[2][id[ver][2]][2]), make_pair(dot[ver].x + now, -1));
                if (it3 != line[2][id[ver][2]][2].end() && dis[(*it3).second][4] > (*it3).first - dot[ver].x) {
                    dis[(*it3).second][4] = (*it3).first - dot[ver].x;
                    pq.push(make_pair(-dis[(*it3).second][4], make_pair((*it3).second, 4)));
                }
            }
            else if (dir[ver] == 1) {
                auto it = lower_bound(all(line[0][id[ver][0]][2]), make_pair(dot[ver].x + (now + 1) / 2, -1));
                if (it != line[0][id[ver][0]][2].end() && dis[(*it).second][0] > 2 * ((*it).first - dot[ver].x)) {
                    dis[(*it).second][0] = 2 * ((*it).first - dot[ver].x);
                    pq.push(make_pair(-dis[(*it).second][0], make_pair((*it).second, 0)));
                }
                auto it2 = lower_bound(all(line[1][id[ver][1]][0]), make_pair(dot[ver].x - (now + 1) / 2 + 1, -1));
                if (it2 != line[1][id[ver][1]][0].begin()) {
                    --it2;
                    if (dis[(*it2).second][3] > 2 * (dot[ver].x - (*it2).first)) {
                        dis[(*it2).second][3] = 2 * (dot[ver].x - (*it2).first);
                        pq.push(make_pair(-dis[(*it2).second][3], make_pair((*it2).second, 3)));
                    }
                }
                auto it3 = lower_bound(all(line[3][id[ver][3]][3]), make_pair(dot[ver].y + now, -1));
                if (it3 != line[3][id[ver][3]][3].end() && dis[(*it3).second][6] > (*it3).first - dot[ver].y) {
                    dis[(*it3).second][6] = (*it3).first - dot[ver].y;
                    pq.push(make_pair(-dis[(*it3).second][6], make_pair((*it3).second, 6)));
                }
            }
            else if (dir[ver] == 2) {
                auto it = lower_bound(all(line[0][id[ver][0]][1]), make_pair(dot[ver].x - (now + 1) / 2 + 1, -1));
                if (it != line[0][id[ver][0]][1].begin()) {
                    --it;
                    if (dis[(*it).second][1] > 2 * (dot[ver].x - (*it).first)) {
                        dis[(*it).second][1] = 2 * (dot[ver].x - (*it).first);
                        pq.push(make_pair(-dis[(*it).second][1], make_pair((*it).second, 1)));
                    }
                }
                auto it2 = lower_bound(all(line[1][id[ver][1]][3]), make_pair(dot[ver].x - (now + 1) / 2 + 1, -1));
                if (it2 != line[1][id[ver][1]][3].begin()) {
                    --it2;
                    if (dis[(*it2).second][3] > 2 * (dot[ver].x - (*it2).first)) {
                        dis[(*it2).second][3] = 2 * (dot[ver].x - (*it2).first);
                        pq.push(make_pair(-dis[(*it2).second][3], make_pair((*it2).second, 3)));
                    }
                }
                auto it3 = lower_bound(all(line[2][id[ver][2]][0]), make_pair(dot[ver].x - now + 1, -1));
                if (it3 != line[2][id[ver][2]][0].begin()) {
                    --it3;
                    if (dis[(*it3).second][5] > dot[ver].x - (*it3).first) {
                        dis[(*it3).second][5] = dot[ver].x - (*it3).first;
                        pq.push(make_pair(-dis[(*it3).second][5], make_pair((*it3).second, 5)));
                    }
                }
            }
            else {
                auto it = lower_bound(all(line[0][id[ver][0]][0]), make_pair(dot[ver].x - (now + 1) / 2 + 1, -1));
                if (it != line[0][id[ver][0]][0].begin()) {
                    --it;
                    if (dis[(*it).second][1] > 2 * (dot[ver].x - (*it).first)) {
                        dis[(*it).second][1] = 2 * (dot[ver].x - (*it).first);
                        pq.push(make_pair(-dis[(*it).second][1], make_pair((*it).second, 1)));
                    }
                }
                auto it2 = lower_bound(all(line[1][id[ver][1]][2]), make_pair(dot[ver].x + (now + 1) / 2, -1));
                if (it2 != line[1][id[ver][1]][2].end() && dis[(*it2).second][2] > 2 * ((*it2).first - dot[ver].x)) {
                    dis[(*it2).second][2] = 2 * ((*it).first - dot[ver].x);
                    pq.push(make_pair(-dis[(*it2).second][2], make_pair((*it2).second, 2)));
                }
                auto it3 = lower_bound(all(line[3][id[ver][3]][1]), make_pair(dot[ver].x - now + 1, -1));
                if (it3 != line[3][id[ver][3]][1].begin()) {
                    --it3;
                    if (dis[(*it3).second][7] > dot[ver].y - (*it3).first) {
                        dis[(*it3).second][7] = dot[ver].y - (*it3).first;
                        pq.push(make_pair(-dis[(*it3).second][7], make_pair((*it3).second, 7)));
                    }
                }
            }
        }
        int res = 1;
        for (int i = 2; i <= N; i++) {
            bool flag = false;
            for (int j = 0; j < 8; j++) flag |= dis[i][j] != inf;
            res += flag;
        }
        ans = max(ans, res);
        for (int i = 2; i <= N; i++) {
            int tmp = dot[i].y;
            dot[i].y = dot[i].x;
            dot[i].x = -tmp;
        }
        dir[1] = 0;
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 59816 KB Output is correct
2 Correct 34 ms 59752 KB Output is correct
3 Correct 32 ms 59808 KB Output is correct
4 Correct 30 ms 59732 KB Output is correct
5 Correct 28 ms 59732 KB Output is correct
6 Correct 36 ms 59700 KB Output is correct
7 Correct 30 ms 59816 KB Output is correct
8 Correct 36 ms 59860 KB Output is correct
9 Correct 33 ms 59840 KB Output is correct
10 Correct 36 ms 59740 KB Output is correct
11 Correct 28 ms 59800 KB Output is correct
12 Correct 33 ms 59780 KB Output is correct
13 Correct 32 ms 59764 KB Output is correct
14 Correct 28 ms 59768 KB Output is correct
15 Correct 27 ms 59752 KB Output is correct
16 Correct 28 ms 59700 KB Output is correct
17 Correct 34 ms 59812 KB Output is correct
18 Correct 34 ms 59744 KB Output is correct
19 Correct 27 ms 59756 KB Output is correct
20 Correct 29 ms 59780 KB Output is correct
21 Correct 35 ms 59752 KB Output is correct
22 Correct 34 ms 59728 KB Output is correct
23 Correct 35 ms 59872 KB Output is correct
24 Correct 34 ms 59740 KB Output is correct
25 Correct 30 ms 59724 KB Output is correct
26 Correct 32 ms 59812 KB Output is correct
27 Correct 29 ms 59748 KB Output is correct
28 Correct 30 ms 59840 KB Output is correct
29 Correct 28 ms 59788 KB Output is correct
30 Incorrect 28 ms 59836 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 59816 KB Output is correct
2 Correct 34 ms 59752 KB Output is correct
3 Correct 32 ms 59808 KB Output is correct
4 Correct 30 ms 59732 KB Output is correct
5 Correct 28 ms 59732 KB Output is correct
6 Correct 36 ms 59700 KB Output is correct
7 Correct 30 ms 59816 KB Output is correct
8 Correct 36 ms 59860 KB Output is correct
9 Correct 33 ms 59840 KB Output is correct
10 Correct 36 ms 59740 KB Output is correct
11 Correct 28 ms 59800 KB Output is correct
12 Correct 33 ms 59780 KB Output is correct
13 Correct 32 ms 59764 KB Output is correct
14 Correct 28 ms 59768 KB Output is correct
15 Correct 27 ms 59752 KB Output is correct
16 Correct 28 ms 59700 KB Output is correct
17 Correct 34 ms 59812 KB Output is correct
18 Correct 34 ms 59744 KB Output is correct
19 Correct 27 ms 59756 KB Output is correct
20 Correct 29 ms 59780 KB Output is correct
21 Correct 35 ms 59752 KB Output is correct
22 Correct 34 ms 59728 KB Output is correct
23 Correct 35 ms 59872 KB Output is correct
24 Correct 34 ms 59740 KB Output is correct
25 Correct 30 ms 59724 KB Output is correct
26 Correct 32 ms 59812 KB Output is correct
27 Correct 29 ms 59748 KB Output is correct
28 Correct 30 ms 59840 KB Output is correct
29 Correct 28 ms 59788 KB Output is correct
30 Incorrect 28 ms 59836 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 59928 KB Output is correct
2 Correct 34 ms 59776 KB Output is correct
3 Correct 37 ms 59776 KB Output is correct
4 Correct 29 ms 59848 KB Output is correct
5 Correct 33 ms 59816 KB Output is correct
6 Correct 35 ms 59852 KB Output is correct
7 Correct 29 ms 59864 KB Output is correct
8 Incorrect 30 ms 59860 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 59816 KB Output is correct
2 Correct 34 ms 59752 KB Output is correct
3 Correct 32 ms 59808 KB Output is correct
4 Correct 30 ms 59732 KB Output is correct
5 Correct 28 ms 59732 KB Output is correct
6 Correct 36 ms 59700 KB Output is correct
7 Correct 30 ms 59816 KB Output is correct
8 Correct 36 ms 59860 KB Output is correct
9 Correct 33 ms 59840 KB Output is correct
10 Correct 36 ms 59740 KB Output is correct
11 Correct 28 ms 59800 KB Output is correct
12 Correct 33 ms 59780 KB Output is correct
13 Correct 32 ms 59764 KB Output is correct
14 Correct 28 ms 59768 KB Output is correct
15 Correct 27 ms 59752 KB Output is correct
16 Correct 28 ms 59700 KB Output is correct
17 Correct 34 ms 59812 KB Output is correct
18 Correct 34 ms 59744 KB Output is correct
19 Correct 27 ms 59756 KB Output is correct
20 Correct 29 ms 59780 KB Output is correct
21 Correct 35 ms 59752 KB Output is correct
22 Correct 34 ms 59728 KB Output is correct
23 Correct 35 ms 59872 KB Output is correct
24 Correct 34 ms 59740 KB Output is correct
25 Correct 30 ms 59724 KB Output is correct
26 Correct 32 ms 59812 KB Output is correct
27 Correct 29 ms 59748 KB Output is correct
28 Correct 30 ms 59840 KB Output is correct
29 Correct 28 ms 59788 KB Output is correct
30 Incorrect 28 ms 59836 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 59816 KB Output is correct
2 Correct 34 ms 59752 KB Output is correct
3 Correct 32 ms 59808 KB Output is correct
4 Correct 30 ms 59732 KB Output is correct
5 Correct 28 ms 59732 KB Output is correct
6 Correct 36 ms 59700 KB Output is correct
7 Correct 30 ms 59816 KB Output is correct
8 Correct 36 ms 59860 KB Output is correct
9 Correct 33 ms 59840 KB Output is correct
10 Correct 36 ms 59740 KB Output is correct
11 Correct 28 ms 59800 KB Output is correct
12 Correct 33 ms 59780 KB Output is correct
13 Correct 32 ms 59764 KB Output is correct
14 Correct 28 ms 59768 KB Output is correct
15 Correct 27 ms 59752 KB Output is correct
16 Correct 28 ms 59700 KB Output is correct
17 Correct 34 ms 59812 KB Output is correct
18 Correct 34 ms 59744 KB Output is correct
19 Correct 27 ms 59756 KB Output is correct
20 Correct 29 ms 59780 KB Output is correct
21 Correct 35 ms 59752 KB Output is correct
22 Correct 34 ms 59728 KB Output is correct
23 Correct 35 ms 59872 KB Output is correct
24 Correct 34 ms 59740 KB Output is correct
25 Correct 30 ms 59724 KB Output is correct
26 Correct 32 ms 59812 KB Output is correct
27 Correct 29 ms 59748 KB Output is correct
28 Correct 30 ms 59840 KB Output is correct
29 Correct 28 ms 59788 KB Output is correct
30 Incorrect 28 ms 59836 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 59816 KB Output is correct
2 Correct 34 ms 59752 KB Output is correct
3 Correct 32 ms 59808 KB Output is correct
4 Correct 30 ms 59732 KB Output is correct
5 Correct 28 ms 59732 KB Output is correct
6 Correct 36 ms 59700 KB Output is correct
7 Correct 30 ms 59816 KB Output is correct
8 Correct 36 ms 59860 KB Output is correct
9 Correct 33 ms 59840 KB Output is correct
10 Correct 36 ms 59740 KB Output is correct
11 Correct 28 ms 59800 KB Output is correct
12 Correct 33 ms 59780 KB Output is correct
13 Correct 32 ms 59764 KB Output is correct
14 Correct 28 ms 59768 KB Output is correct
15 Correct 27 ms 59752 KB Output is correct
16 Correct 28 ms 59700 KB Output is correct
17 Correct 34 ms 59812 KB Output is correct
18 Correct 34 ms 59744 KB Output is correct
19 Correct 27 ms 59756 KB Output is correct
20 Correct 29 ms 59780 KB Output is correct
21 Correct 35 ms 59752 KB Output is correct
22 Correct 34 ms 59728 KB Output is correct
23 Correct 35 ms 59872 KB Output is correct
24 Correct 34 ms 59740 KB Output is correct
25 Correct 30 ms 59724 KB Output is correct
26 Correct 32 ms 59812 KB Output is correct
27 Correct 29 ms 59748 KB Output is correct
28 Correct 30 ms 59840 KB Output is correct
29 Correct 28 ms 59788 KB Output is correct
30 Incorrect 28 ms 59836 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 59816 KB Output is correct
2 Correct 34 ms 59752 KB Output is correct
3 Correct 32 ms 59808 KB Output is correct
4 Correct 30 ms 59732 KB Output is correct
5 Correct 28 ms 59732 KB Output is correct
6 Correct 36 ms 59700 KB Output is correct
7 Correct 30 ms 59816 KB Output is correct
8 Correct 36 ms 59860 KB Output is correct
9 Correct 33 ms 59840 KB Output is correct
10 Correct 36 ms 59740 KB Output is correct
11 Correct 28 ms 59800 KB Output is correct
12 Correct 33 ms 59780 KB Output is correct
13 Correct 32 ms 59764 KB Output is correct
14 Correct 28 ms 59768 KB Output is correct
15 Correct 27 ms 59752 KB Output is correct
16 Correct 28 ms 59700 KB Output is correct
17 Correct 34 ms 59812 KB Output is correct
18 Correct 34 ms 59744 KB Output is correct
19 Correct 27 ms 59756 KB Output is correct
20 Correct 29 ms 59780 KB Output is correct
21 Correct 35 ms 59752 KB Output is correct
22 Correct 34 ms 59728 KB Output is correct
23 Correct 35 ms 59872 KB Output is correct
24 Correct 34 ms 59740 KB Output is correct
25 Correct 30 ms 59724 KB Output is correct
26 Correct 32 ms 59812 KB Output is correct
27 Correct 29 ms 59748 KB Output is correct
28 Correct 30 ms 59840 KB Output is correct
29 Correct 28 ms 59788 KB Output is correct
30 Incorrect 28 ms 59836 KB Output isn't correct
31 Halted 0 ms 0 KB -