Submission #795281

# Submission time Handle Problem Language Result Execution time Memory
795281 2023-07-27T08:02:20 Z vjudge1 Team Contest (JOI22_team) C++17
55 / 100
2000 ms 376596 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 it3 = it2->second.upper_bound(y); it3 != it2->second.end(); ++ it3) {
                        int y2 = it3->first, z2 = it3->second;
                        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;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 2388 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 1088 KB Output is correct
17 Correct 2 ms 776 KB Output is correct
18 Correct 2 ms 1888 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 2388 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 1088 KB Output is correct
17 Correct 2 ms 776 KB Output is correct
18 Correct 2 ms 1888 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1356 ms 376596 KB Output is correct
27 Correct 684 ms 158476 KB Output is correct
28 Correct 596 ms 142464 KB Output is correct
29 Correct 390 ms 92176 KB Output is correct
30 Correct 84 ms 35068 KB Output is correct
31 Correct 82 ms 15444 KB Output is correct
32 Correct 24 ms 2084 KB Output is correct
33 Correct 26 ms 468 KB Output is correct
34 Correct 949 ms 375312 KB Output is correct
35 Correct 2 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 27 ms 12932 KB Output is correct
38 Correct 27 ms 12904 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 21 ms 2096 KB Output is correct
12 Correct 14 ms 1512 KB Output is correct
13 Correct 16 ms 1760 KB Output is correct
14 Correct 21 ms 2108 KB Output is correct
15 Correct 19 ms 2004 KB Output is correct
16 Correct 18 ms 2104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 21 ms 2096 KB Output is correct
12 Correct 14 ms 1512 KB Output is correct
13 Correct 16 ms 1760 KB Output is correct
14 Correct 21 ms 2108 KB Output is correct
15 Correct 19 ms 2004 KB Output is correct
16 Correct 18 ms 2104 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 28 ms 2104 KB Output is correct
23 Correct 23 ms 2132 KB Output is correct
24 Correct 19 ms 1620 KB Output is correct
25 Correct 26 ms 2096 KB Output is correct
26 Correct 21 ms 2080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 21 ms 2096 KB Output is correct
12 Correct 14 ms 1512 KB Output is correct
13 Correct 16 ms 1760 KB Output is correct
14 Correct 21 ms 2108 KB Output is correct
15 Correct 19 ms 2004 KB Output is correct
16 Correct 18 ms 2104 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 28 ms 2104 KB Output is correct
23 Correct 23 ms 2132 KB Output is correct
24 Correct 19 ms 1620 KB Output is correct
25 Correct 26 ms 2096 KB Output is correct
26 Correct 21 ms 2080 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 25 ms 2088 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Execution timed out 2080 ms 7024 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 21 ms 2096 KB Output is correct
12 Correct 14 ms 1512 KB Output is correct
13 Correct 16 ms 1760 KB Output is correct
14 Correct 21 ms 2108 KB Output is correct
15 Correct 19 ms 2004 KB Output is correct
16 Correct 18 ms 2104 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 28 ms 2104 KB Output is correct
23 Correct 23 ms 2132 KB Output is correct
24 Correct 19 ms 1620 KB Output is correct
25 Correct 26 ms 2096 KB Output is correct
26 Correct 21 ms 2080 KB Output is correct
27 Correct 2 ms 1876 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 25 ms 2088 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Execution timed out 2080 ms 7024 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 6 ms 2388 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 1088 KB Output is correct
17 Correct 2 ms 776 KB Output is correct
18 Correct 2 ms 1888 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 4 ms 2260 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1356 ms 376596 KB Output is correct
27 Correct 684 ms 158476 KB Output is correct
28 Correct 596 ms 142464 KB Output is correct
29 Correct 390 ms 92176 KB Output is correct
30 Correct 84 ms 35068 KB Output is correct
31 Correct 82 ms 15444 KB Output is correct
32 Correct 24 ms 2084 KB Output is correct
33 Correct 26 ms 468 KB Output is correct
34 Correct 949 ms 375312 KB Output is correct
35 Correct 2 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 27 ms 12932 KB Output is correct
38 Correct 27 ms 12904 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 21 ms 2096 KB Output is correct
51 Correct 14 ms 1512 KB Output is correct
52 Correct 16 ms 1760 KB Output is correct
53 Correct 21 ms 2108 KB Output is correct
54 Correct 19 ms 2004 KB Output is correct
55 Correct 18 ms 2104 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 28 ms 2104 KB Output is correct
62 Correct 23 ms 2132 KB Output is correct
63 Correct 19 ms 1620 KB Output is correct
64 Correct 26 ms 2096 KB Output is correct
65 Correct 21 ms 2080 KB Output is correct
66 Correct 2 ms 1876 KB Output is correct
67 Correct 1 ms 852 KB Output is correct
68 Correct 1 ms 724 KB Output is correct
69 Correct 1 ms 724 KB Output is correct
70 Correct 25 ms 2088 KB Output is correct
71 Correct 2 ms 1876 KB Output is correct
72 Correct 2 ms 1876 KB Output is correct
73 Execution timed out 2080 ms 7024 KB Time limit exceeded
74 Halted 0 ms 0 KB -