답안 #795236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795236 2023-07-27T07:43:30 Z vjudge1 Team Contest (JOI22_team) C++17
64 / 100
195 ms 13136 KB
#include<bits/stdc++.h>

using namespace std;


struct person {
    int x, y, z;
};

const int N = 150000;

int w[300 + 10][300 + 10];

void add(int A, int B) {
    w[A][B] = max(w[A][B], A + B);
}
void build() {
    for(int i = 300; i >= 0; i--) {
        for(int j = 300; j >= 0; j--) {
            w[i][j] = max({w[i][j + 1], w[i + 1][j], w[i][j]});
        }
    }
}

vector<pair<int, int>> pnts[N + 10];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<person> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y >> a[i].z;
    }
    if(n <= 4000) {
        sort(a.begin(), a.end(), [](person l, person r) {return l.z < r.z;});
        int ans = 0;
        for(int i = 0; i < n; i++) {
            // cout << a[i].x << ' ' << a[i].y << ' ' << a[i].z << '\n';
            int Y = 0, l = i + 1;
            for(int j = i + 1; j < n; j++) {
                if(a[j].x >= a[i].x || a[j].z == a[i].z) continue;
                while (a[l].z < a[j].z) {
                    if(a[l].x < a[i].x) Y = max(Y, a[l].y);
                    l++;
                }

                if(Y > max(a[i].y, a[j].y)) {
                    ans = max(ans, a[i].x + Y + a[j].z);
                }
            }
            int X = 0, r = i + 1;
            for(int j = i + 1; j < n; j++) {
                if(a[j].y >= a[i].y || a[j].z == a[i].z) continue;
                while (a[r].z < a[j].z) {
                    if(a[r].y < a[i].y) X = max(X, a[r].x);
                    r++;
                }

                if(X > max(a[i].x, a[j].x)) {
                    ans = max(ans, a[i].y + X + a[j].z);
                }
            }

        }
        if(ans == 0) ans = -1;
        cout << ans;
        return 0;
    }
    sort(a.begin(), a.end(), [](person l, person r) {return l.x < r.x;});
    
    int mxZ[300 + 10] = {}, mxY[300 + 10] = {};
    for(int i = 0; i < n; i++) {
        mxY[a[i].z] = max(mxY[a[i].z], a[i].y);
        mxZ[a[i].y] = max(mxZ[a[i].y], a[i].z);
        for(int j = a[i].z + 1; j <= 300; j++) 
            mxY[j] = max(mxY[j], mxY[j - 1]);
        for(int j = a[i].y + 1; j <= 300; j++) 
            mxZ[j] = max(mxZ[j], mxZ[j - 1]);
        if(mxZ[a[i].y - 1] > a[i].z) 
            pnts[i].push_back({a[i].y, mxZ[a[i].y - 1]});
        if(mxY[a[i].z - 1] > a[i].y) 
            pnts[i].push_back({mxY[a[i].z - 1], a[i].z});
    }
    int res = 0;
    int l = 0;
    for(int i = 0; i < n; i++) {
        while(a[l].x < a[i].x) {
            for(auto [A, B] : pnts[l]) {
                add(A, B);
            }
            l++;
        }
        if(i && a[i].x != a[i - 1].x) build();
        if(w[a[i].y + 1][a[i].z + 1]) 
            res = max(a[i].x + w[a[i].y + 1][a[i].z + 1], res);
    }
    if(res == 0) cout << -1;
    else cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3848 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3844 KB Output is correct
9 Correct 2 ms 3848 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 2 ms 3852 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 2 ms 3852 KB Output is correct
15 Correct 2 ms 3852 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 3 ms 3856 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3796 KB Output is correct
20 Correct 2 ms 3796 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 2 ms 3856 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 2 ms 3796 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3848 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3844 KB Output is correct
9 Correct 2 ms 3848 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 2 ms 3852 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 2 ms 3852 KB Output is correct
15 Correct 2 ms 3852 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 3 ms 3856 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3796 KB Output is correct
20 Correct 2 ms 3796 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 2 ms 3856 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 2 ms 3796 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
26 Correct 69 ms 3984 KB Output is correct
27 Correct 94 ms 3988 KB Output is correct
28 Correct 82 ms 3984 KB Output is correct
29 Correct 62 ms 3988 KB Output is correct
30 Correct 40 ms 3896 KB Output is correct
31 Correct 109 ms 3928 KB Output is correct
32 Correct 100 ms 3920 KB Output is correct
33 Correct 29 ms 3924 KB Output is correct
34 Correct 18 ms 3924 KB Output is correct
35 Correct 3 ms 3840 KB Output is correct
36 Correct 3 ms 3860 KB Output is correct
37 Correct 22 ms 3856 KB Output is correct
38 Correct 18 ms 3924 KB Output is correct
39 Correct 26 ms 3872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3848 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3852 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 2 ms 3844 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 124 ms 10888 KB Output is correct
12 Correct 79 ms 7912 KB Output is correct
13 Correct 93 ms 6656 KB Output is correct
14 Correct 116 ms 9876 KB Output is correct
15 Correct 111 ms 9184 KB Output is correct
16 Correct 108 ms 6376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3848 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3852 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 2 ms 3844 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 124 ms 10888 KB Output is correct
12 Correct 79 ms 7912 KB Output is correct
13 Correct 93 ms 6656 KB Output is correct
14 Correct 116 ms 9876 KB Output is correct
15 Correct 111 ms 9184 KB Output is correct
16 Correct 108 ms 6376 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3796 KB Output is correct
20 Correct 2 ms 3796 KB Output is correct
21 Correct 26 ms 3864 KB Output is correct
22 Correct 128 ms 11640 KB Output is correct
23 Correct 123 ms 11020 KB Output is correct
24 Correct 93 ms 8736 KB Output is correct
25 Correct 123 ms 10196 KB Output is correct
26 Correct 111 ms 9200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3848 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3852 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 2 ms 3844 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 124 ms 10888 KB Output is correct
12 Correct 79 ms 7912 KB Output is correct
13 Correct 93 ms 6656 KB Output is correct
14 Correct 116 ms 9876 KB Output is correct
15 Correct 111 ms 9184 KB Output is correct
16 Correct 108 ms 6376 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3796 KB Output is correct
20 Correct 2 ms 3796 KB Output is correct
21 Correct 26 ms 3864 KB Output is correct
22 Correct 128 ms 11640 KB Output is correct
23 Correct 123 ms 11020 KB Output is correct
24 Correct 93 ms 8736 KB Output is correct
25 Correct 123 ms 10196 KB Output is correct
26 Correct 111 ms 9200 KB Output is correct
27 Correct 3 ms 3796 KB Output is correct
28 Correct 2 ms 3796 KB Output is correct
29 Correct 2 ms 3852 KB Output is correct
30 Correct 2 ms 3796 KB Output is correct
31 Correct 102 ms 3924 KB Output is correct
32 Correct 3 ms 3796 KB Output is correct
33 Correct 3 ms 3796 KB Output is correct
34 Correct 185 ms 11860 KB Output is correct
35 Correct 186 ms 10872 KB Output is correct
36 Correct 195 ms 11460 KB Output is correct
37 Correct 175 ms 10732 KB Output is correct
38 Correct 180 ms 9668 KB Output is correct
39 Correct 47 ms 8648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3848 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3852 KB Output is correct
6 Correct 3 ms 3796 KB Output is correct
7 Correct 2 ms 3844 KB Output is correct
8 Correct 2 ms 3796 KB Output is correct
9 Correct 2 ms 3796 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 124 ms 10888 KB Output is correct
12 Correct 79 ms 7912 KB Output is correct
13 Correct 93 ms 6656 KB Output is correct
14 Correct 116 ms 9876 KB Output is correct
15 Correct 111 ms 9184 KB Output is correct
16 Correct 108 ms 6376 KB Output is correct
17 Correct 2 ms 3796 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3796 KB Output is correct
20 Correct 2 ms 3796 KB Output is correct
21 Correct 26 ms 3864 KB Output is correct
22 Correct 128 ms 11640 KB Output is correct
23 Correct 123 ms 11020 KB Output is correct
24 Correct 93 ms 8736 KB Output is correct
25 Correct 123 ms 10196 KB Output is correct
26 Correct 111 ms 9200 KB Output is correct
27 Correct 3 ms 3796 KB Output is correct
28 Correct 2 ms 3796 KB Output is correct
29 Correct 2 ms 3852 KB Output is correct
30 Correct 2 ms 3796 KB Output is correct
31 Correct 102 ms 3924 KB Output is correct
32 Correct 3 ms 3796 KB Output is correct
33 Correct 3 ms 3796 KB Output is correct
34 Correct 185 ms 11860 KB Output is correct
35 Correct 186 ms 10872 KB Output is correct
36 Correct 195 ms 11460 KB Output is correct
37 Correct 175 ms 10732 KB Output is correct
38 Correct 180 ms 9668 KB Output is correct
39 Correct 47 ms 8648 KB Output is correct
40 Correct 39 ms 3896 KB Output is correct
41 Correct 108 ms 3924 KB Output is correct
42 Correct 18 ms 3924 KB Output is correct
43 Correct 18 ms 3924 KB Output is correct
44 Runtime error 38 ms 13136 KB Execution killed with signal 11
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3796 KB Output is correct
2 Correct 2 ms 3848 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 2 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 2 ms 3796 KB Output is correct
8 Correct 2 ms 3844 KB Output is correct
9 Correct 2 ms 3848 KB Output is correct
10 Correct 2 ms 3796 KB Output is correct
11 Correct 2 ms 3852 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 2 ms 3852 KB Output is correct
15 Correct 2 ms 3852 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 3 ms 3856 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3796 KB Output is correct
20 Correct 2 ms 3796 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 2 ms 3856 KB Output is correct
23 Correct 2 ms 3796 KB Output is correct
24 Correct 2 ms 3796 KB Output is correct
25 Correct 3 ms 3796 KB Output is correct
26 Correct 69 ms 3984 KB Output is correct
27 Correct 94 ms 3988 KB Output is correct
28 Correct 82 ms 3984 KB Output is correct
29 Correct 62 ms 3988 KB Output is correct
30 Correct 40 ms 3896 KB Output is correct
31 Correct 109 ms 3928 KB Output is correct
32 Correct 100 ms 3920 KB Output is correct
33 Correct 29 ms 3924 KB Output is correct
34 Correct 18 ms 3924 KB Output is correct
35 Correct 3 ms 3840 KB Output is correct
36 Correct 3 ms 3860 KB Output is correct
37 Correct 22 ms 3856 KB Output is correct
38 Correct 18 ms 3924 KB Output is correct
39 Correct 26 ms 3872 KB Output is correct
40 Correct 2 ms 3796 KB Output is correct
41 Correct 2 ms 3796 KB Output is correct
42 Correct 2 ms 3848 KB Output is correct
43 Correct 2 ms 3796 KB Output is correct
44 Correct 2 ms 3852 KB Output is correct
45 Correct 3 ms 3796 KB Output is correct
46 Correct 2 ms 3844 KB Output is correct
47 Correct 2 ms 3796 KB Output is correct
48 Correct 2 ms 3796 KB Output is correct
49 Correct 2 ms 3796 KB Output is correct
50 Correct 124 ms 10888 KB Output is correct
51 Correct 79 ms 7912 KB Output is correct
52 Correct 93 ms 6656 KB Output is correct
53 Correct 116 ms 9876 KB Output is correct
54 Correct 111 ms 9184 KB Output is correct
55 Correct 108 ms 6376 KB Output is correct
56 Correct 2 ms 3796 KB Output is correct
57 Correct 2 ms 3796 KB Output is correct
58 Correct 2 ms 3796 KB Output is correct
59 Correct 2 ms 3796 KB Output is correct
60 Correct 26 ms 3864 KB Output is correct
61 Correct 128 ms 11640 KB Output is correct
62 Correct 123 ms 11020 KB Output is correct
63 Correct 93 ms 8736 KB Output is correct
64 Correct 123 ms 10196 KB Output is correct
65 Correct 111 ms 9200 KB Output is correct
66 Correct 3 ms 3796 KB Output is correct
67 Correct 2 ms 3796 KB Output is correct
68 Correct 2 ms 3852 KB Output is correct
69 Correct 2 ms 3796 KB Output is correct
70 Correct 102 ms 3924 KB Output is correct
71 Correct 3 ms 3796 KB Output is correct
72 Correct 3 ms 3796 KB Output is correct
73 Correct 185 ms 11860 KB Output is correct
74 Correct 186 ms 10872 KB Output is correct
75 Correct 195 ms 11460 KB Output is correct
76 Correct 175 ms 10732 KB Output is correct
77 Correct 180 ms 9668 KB Output is correct
78 Correct 47 ms 8648 KB Output is correct
79 Correct 39 ms 3896 KB Output is correct
80 Correct 108 ms 3924 KB Output is correct
81 Correct 18 ms 3924 KB Output is correct
82 Correct 18 ms 3924 KB Output is correct
83 Runtime error 38 ms 13136 KB Execution killed with signal 11
84 Halted 0 ms 0 KB -