답안 #795273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795273 2023-07-27T07:59:20 Z vjudge1 Team Contest (JOI22_team) C++17
55 / 100
2000 ms 376664 KB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

struct My{
    int x, y, z;

    bool operator < (My &b) {
        return x == b.x ? (y == b.y ? z < b.z : y < b.y) : x < b.x;
    }
};

map < int , map < int, int > > mp;

int get(int x, int y) {
    auto it = mp.lower_bound(x);
    if(it == mp.begin()) {
        return 0;
    }
    -- it;
    auto it2 = it->second.lower_bound(y);
    if(it2 == it->second.begin()) {
        return 0;
    }
    -- it2;
    return it2->second;
}

int mtx[4040][4040];

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m, k, mx = 0;
    cin >> n;
    vector < My > V(n);
    for(auto &[x, y, z] : V) {
        cin >> x >> y >> z;
        mx = max({mx, x, y, z});
    }
    if(mx <= 4000) {
        for(auto &[x, y, z] : V) {
            mtx[x][y] = max(mtx[x][y], z);
            auto it = mp.find(x);
            if(it == mp.end()) {
                mp[x];
                it = mp.find(x);
            }
            auto it2 = it->second.find(y);
            if(it2 == it->second.end()) {
                it->second[y] = z;
            } else {
                it2->second = min(it2->second, z);
            }
        }
        for(int i = 1; i <= mx; ++ i) {
            for(int j = 1; j <= mx; ++j) {
                mtx[i][j] = max({mtx[i][j], mtx[i][j - 1], mtx[i - 1][j]});
            }
        }
        mx = 0;
        for(auto it = prev(mp.end());  it != mp.begin(); it --) {
            int x = it->first;
            for(auto &[y, z] : it->second) {
                for(auto it2 = prev(it);; it2 --) {
                    int x2 = it2->first;
                    if(x2 >= x) {
                        continue;
                    }
                    for(auto &[y2, z2] : it2->second) {
                        if(y2 <= y) {
                            continue;
                        }
                        k = mtx[x - 1][y2 - 1];
                        if(k > z && k > z2) {
                            mx = max(mx, x + y2 + k);
                        }
                    }
                    if(it2 == mp.begin()) {
                        break;
                    }
                }
            }
        }
        cout << (mx ? mx : -1);
        return 0;
    }
    sort(V.begin(), V.end());
    for(int i = 0; i < n; ++ i) {
        auto it = mp.find(V[i].x);
        if(it == mp.end()) {
            mp[V[i].x];
            it = mp.find(V[i].x);
        }
        auto it2 = it->second.find(V[i].y);
        if(it2 == it->second.end()) {
            it->second[V[i].y] = V[i].z;
        } else {
            it2->second = max(it2->second, V[i].z);
        }
        if(i + 1 < n && V[i].x == V[i + 1].x) {
            continue;
        }
        if(it != mp.begin()) {
            auto pre_mp = prev(it);
            for(auto &[key, val] : pre_mp->second) {
                auto it2 = it->second.find(key);
                if(it2 == it->second.end()) {
                    it->second[key] = val;
                } else {
                    it2->second = max(it2->second, val);
                }
            }
        } 
        mx = 0;
        for(auto &[key, val] : it->second) {
            mx = max(mx, val);
            val = mx;
        }
    }
    /**
    for(auto &[x, y, z] : V) {
        cout << x << ' ' << y << ' ' << z << '\n';
    }
    cout << '\n';
    for(auto &[key, val] : mp) {
        for(auto &[key2, val2] : val) {
            cout << key << ' ' << key2 << ' ' << val2 << '\n';
        }
    }
    // */
    mx = 0;
    for(int i = n; i --> 0;) {
        for(int j = i; j --> 0;) {
            if(V[i].x > V[j].x && V[j].y > V[i].y) {
                k = get(V[i].x, V[j].y);
                if(k > V[i].z && k > V[j].z) {
                    mx = max(mx, V[i].x + V[j].y + k);
                }
            }
        }
    }
    cout << (mx ? mx : -1);
} 

Compilation message

team.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main() {
      | ^~~~
team.cpp: In function 'int main()':
team.cpp:45:12: warning: unused variable 'm' [-Wunused-variable]
   45 |     int n, m, k, mx = 0;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 6 ms 2380 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 356 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 1 ms 388 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 6 ms 2380 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 356 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 1 ms 388 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 716 KB Output is correct
26 Correct 1346 ms 376664 KB Output is correct
27 Correct 675 ms 158580 KB Output is correct
28 Correct 600 ms 142688 KB Output is correct
29 Correct 368 ms 92272 KB Output is correct
30 Correct 93 ms 35092 KB Output is correct
31 Correct 107 ms 15496 KB Output is correct
32 Correct 33 ms 2128 KB Output is correct
33 Correct 29 ms 596 KB Output is correct
34 Correct 932 ms 375536 KB Output is correct
35 Correct 3 ms 1876 KB Output is correct
36 Correct 3 ms 1876 KB Output is correct
37 Correct 37 ms 12884 KB Output is correct
38 Correct 37 ms 12884 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 27 ms 2344 KB Output is correct
12 Correct 16 ms 1560 KB Output is correct
13 Correct 17 ms 1840 KB Output is correct
14 Correct 21 ms 2212 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
16 Correct 18 ms 2184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 27 ms 2344 KB Output is correct
12 Correct 16 ms 1560 KB Output is correct
13 Correct 17 ms 1840 KB Output is correct
14 Correct 21 ms 2212 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
16 Correct 18 ms 2184 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 28 ms 2252 KB Output is correct
23 Correct 25 ms 2180 KB Output is correct
24 Correct 19 ms 1876 KB Output is correct
25 Correct 27 ms 2228 KB Output is correct
26 Correct 22 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 27 ms 2344 KB Output is correct
12 Correct 16 ms 1560 KB Output is correct
13 Correct 17 ms 1840 KB Output is correct
14 Correct 21 ms 2212 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
16 Correct 18 ms 2184 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 28 ms 2252 KB Output is correct
23 Correct 25 ms 2180 KB Output is correct
24 Correct 19 ms 1876 KB Output is correct
25 Correct 27 ms 2228 KB Output is correct
26 Correct 22 ms 2252 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 916 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 712 KB Output is correct
31 Correct 33 ms 2132 KB Output is correct
32 Correct 3 ms 1868 KB Output is correct
33 Correct 3 ms 1876 KB Output is correct
34 Execution timed out 2039 ms 7528 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 276 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 27 ms 2344 KB Output is correct
12 Correct 16 ms 1560 KB Output is correct
13 Correct 17 ms 1840 KB Output is correct
14 Correct 21 ms 2212 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
16 Correct 18 ms 2184 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 28 ms 2252 KB Output is correct
23 Correct 25 ms 2180 KB Output is correct
24 Correct 19 ms 1876 KB Output is correct
25 Correct 27 ms 2228 KB Output is correct
26 Correct 22 ms 2252 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 916 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 712 KB Output is correct
31 Correct 33 ms 2132 KB Output is correct
32 Correct 3 ms 1868 KB Output is correct
33 Correct 3 ms 1876 KB Output is correct
34 Execution timed out 2039 ms 7528 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 6 ms 2380 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 2 ms 716 KB Output is correct
18 Correct 2 ms 1876 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 356 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 1 ms 388 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 716 KB Output is correct
26 Correct 1346 ms 376664 KB Output is correct
27 Correct 675 ms 158580 KB Output is correct
28 Correct 600 ms 142688 KB Output is correct
29 Correct 368 ms 92272 KB Output is correct
30 Correct 93 ms 35092 KB Output is correct
31 Correct 107 ms 15496 KB Output is correct
32 Correct 33 ms 2128 KB Output is correct
33 Correct 29 ms 596 KB Output is correct
34 Correct 932 ms 375536 KB Output is correct
35 Correct 3 ms 1876 KB Output is correct
36 Correct 3 ms 1876 KB Output is correct
37 Correct 37 ms 12884 KB Output is correct
38 Correct 37 ms 12884 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 276 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 27 ms 2344 KB Output is correct
51 Correct 16 ms 1560 KB Output is correct
52 Correct 17 ms 1840 KB Output is correct
53 Correct 21 ms 2212 KB Output is correct
54 Correct 19 ms 2132 KB Output is correct
55 Correct 18 ms 2184 KB Output is correct
56 Correct 1 ms 328 KB Output is correct
57 Correct 1 ms 320 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 28 ms 2252 KB Output is correct
62 Correct 25 ms 2180 KB Output is correct
63 Correct 19 ms 1876 KB Output is correct
64 Correct 27 ms 2228 KB Output is correct
65 Correct 22 ms 2252 KB Output is correct
66 Correct 2 ms 1876 KB Output is correct
67 Correct 1 ms 916 KB Output is correct
68 Correct 1 ms 724 KB Output is correct
69 Correct 1 ms 712 KB Output is correct
70 Correct 33 ms 2132 KB Output is correct
71 Correct 3 ms 1868 KB Output is correct
72 Correct 3 ms 1876 KB Output is correct
73 Execution timed out 2039 ms 7528 KB Time limit exceeded
74 Halted 0 ms 0 KB -