Submission #921565

# Submission time Handle Problem Language Result Execution time Memory
921565 2024-02-04T06:45:31 Z vjudge1 Team Contest (JOI22_team) C++17
100 / 100
950 ms 71252 KB
#pragma GCC optimize("unroll-loops")
#pragma gcc optimize("Ofast")
#pragma GCC optimization("Ofast")
#pragma optimize(Ofast)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define str string
#define fastio ios::sync_with_stdio(0), cin.tie(0);
#define fs first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define len(x) x.size()

#define print(a)          \
    for (auto &x : a)     \
        cout << x << " "; \
    cout << endl;

#define printmp(a)    \
    for (auto &x : a) \
        cout << x.fs << " " << x.ss << endl;

const int mod = 998244353;

void solve(){
    int n;
    cin >> n;
    vector<array<int, 3>> a(n);
    for(int i = 0; i < n; i ++)
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    set<int, greater<int>> a1, a2, a3;
    for(int i = 0; i < n; i ++)
        a1.insert(a[i][0]), a2.insert(a[i][1]), a3.insert(a[i][2]);
    map<int, int> mp1, mp2, mp3;
    for(auto x : a1)
        mp1[x] = mp1.size();
    for(auto x : a2)
        mp2[x] = mp2.size();
    for(auto x : a3)
        mp3[x] = mp3.size();
    vector<int> cnt1(n + 1), cnt2(n + 1), cnt3(n + 1);
    for(int i = 0; i < n; i ++)
        cnt1[mp1[a[i][0]]] ++, cnt2[mp2[a[i][1]]] ++, cnt3[mp3[a[i][2]]] ++;
    vector<bool> removed(n);
    set<array<int, 2>, greater<array<int, 2>>> s1, s2, s3;
    for(int i = 0; i < n; i ++){
        s1.insert({a[i][0] + a[i][1], i});
        s2.insert({a[i][0] + a[i][2], i});
        s3.insert({a[i][1] + a[i][2], i});
    }
    while(!s1.empty() && !s2.empty() && !s3.empty()){
        array<int, 2> x = *s1.begin(), y = *s2.begin(), z = *s3.begin();
        if(*a1.begin() + *a2.begin() == x[0] && !removed[x[1]]){
            removed[x[1]] = true;
            cnt1[mp1[a[x[1]][0]]] --;
            cnt2[mp2[a[x[1]][1]]] --;
            cnt3[mp3[a[x[1]][2]]] --;
            s1.erase(s1.begin());
            s2.erase({a[x[1]][0] + a[x[1]][2], x[1]});
            s3.erase({a[x[1]][1] + a[x[1]][2], x[1]});
            if(cnt1[mp1[a[x[1]][0]]] == 0)
                a1.erase(a1.begin());
            if(cnt2[mp2[a[x[1]][1]]] == 0)
                a2.erase(a2.begin());
            if(cnt3[mp3[a[x[1]][2]]] == 0)
                a3.erase(a3.find(a[x[1]][2]));
        }
        else if(*a1.begin() + *a3.begin() == y[0] && !removed[y[1]]){
            removed[y[1]] = true;
            cnt1[mp1[a[y[1]][0]]] --;
            cnt2[mp2[a[y[1]][1]]] --;
            cnt3[mp3[a[y[1]][2]]] --;
            s1.erase({a[y[1]][0] + a[y[1]][1], y[1]});
            s2.erase(s2.begin());
            s3.erase({a[y[1]][1] + a[y[1]][2], y[1]});
            if(cnt1[mp1[a[y[1]][0]]] == 0)
                a1.erase(a1.begin());
            if(cnt2[mp2[a[y[1]][1]]] == 0)
                a2.erase(a2.find(a[y[1]][1]));
            if(cnt3[mp3[a[y[1]][2]]] == 0)
                a3.erase(a3.begin());
        }
        else if(*a2.begin() + *a3.begin() == z[0] && !removed[z[1]]){
            removed[z[1]] = true;
            cnt1[mp1[a[z[1]][0]]] --;
            cnt2[mp2[a[z[1]][1]]] --;
            cnt3[mp3[a[z[1]][2]]] --;
            s1.erase({a[z[1]][0] + a[z[1]][1], z[1]});
            s2.erase({a[z[1]][0] + a[z[1]][2], z[1]});
            s3.erase(s3.begin());
            if(cnt1[mp1[a[z[1]][0]]] == 0)
                a1.erase(a1.find(a[z[1]][0]));
            if(cnt2[mp2[a[z[1]][1]]] == 0)
                a2.erase(a2.begin());
            if(cnt3[mp3[a[z[1]][2]]] == 0)
                a3.erase(a3.begin());
        }
        else{
            break;
        }
    }
    if(a1.empty())
        cout << -1;
    else
        cout << *a1.begin() + *a2.begin() + *a3.begin();
}

signed main()
{
    fastio int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        // cout << endl;
    }
}

Compilation message

team.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("Ofast")
      | 
team.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("Ofast")
      | 
team.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    4 | #pragma optimize(Ofast)
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 504 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 504 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 7 ms 2140 KB Output is correct
27 Correct 7 ms 1884 KB Output is correct
28 Correct 7 ms 1628 KB Output is correct
29 Correct 11 ms 1628 KB Output is correct
30 Correct 5 ms 1112 KB Output is correct
31 Correct 6 ms 1372 KB Output is correct
32 Correct 6 ms 1116 KB Output is correct
33 Correct 6 ms 1372 KB Output is correct
34 Correct 9 ms 2136 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 4 ms 1372 KB Output is correct
38 Correct 5 ms 1488 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 160 ms 24964 KB Output is correct
12 Correct 134 ms 17484 KB Output is correct
13 Correct 100 ms 21332 KB Output is correct
14 Correct 222 ms 26208 KB Output is correct
15 Correct 153 ms 26012 KB Output is correct
16 Correct 128 ms 25828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 160 ms 24964 KB Output is correct
12 Correct 134 ms 17484 KB Output is correct
13 Correct 100 ms 21332 KB Output is correct
14 Correct 222 ms 26208 KB Output is correct
15 Correct 153 ms 26012 KB Output is correct
16 Correct 128 ms 25828 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 192 ms 26252 KB Output is correct
23 Correct 218 ms 25448 KB Output is correct
24 Correct 192 ms 19284 KB Output is correct
25 Correct 274 ms 26232 KB Output is correct
26 Correct 160 ms 25940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 160 ms 24964 KB Output is correct
12 Correct 134 ms 17484 KB Output is correct
13 Correct 100 ms 21332 KB Output is correct
14 Correct 222 ms 26208 KB Output is correct
15 Correct 153 ms 26012 KB Output is correct
16 Correct 128 ms 25828 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 192 ms 26252 KB Output is correct
23 Correct 218 ms 25448 KB Output is correct
24 Correct 192 ms 19284 KB Output is correct
25 Correct 274 ms 26232 KB Output is correct
26 Correct 160 ms 25940 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 6 ms 1116 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 265 ms 25544 KB Output is correct
35 Correct 308 ms 24448 KB Output is correct
36 Correct 294 ms 26704 KB Output is correct
37 Correct 402 ms 26704 KB Output is correct
38 Correct 228 ms 26160 KB Output is correct
39 Correct 133 ms 16176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 160 ms 24964 KB Output is correct
12 Correct 134 ms 17484 KB Output is correct
13 Correct 100 ms 21332 KB Output is correct
14 Correct 222 ms 26208 KB Output is correct
15 Correct 153 ms 26012 KB Output is correct
16 Correct 128 ms 25828 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 192 ms 26252 KB Output is correct
23 Correct 218 ms 25448 KB Output is correct
24 Correct 192 ms 19284 KB Output is correct
25 Correct 274 ms 26232 KB Output is correct
26 Correct 160 ms 25940 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 6 ms 1116 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 265 ms 25544 KB Output is correct
35 Correct 308 ms 24448 KB Output is correct
36 Correct 294 ms 26704 KB Output is correct
37 Correct 402 ms 26704 KB Output is correct
38 Correct 228 ms 26160 KB Output is correct
39 Correct 133 ms 16176 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 5 ms 1372 KB Output is correct
42 Correct 4 ms 1372 KB Output is correct
43 Correct 7 ms 1372 KB Output is correct
44 Correct 355 ms 28160 KB Output is correct
45 Correct 544 ms 28272 KB Output is correct
46 Correct 402 ms 28244 KB Output is correct
47 Correct 543 ms 28468 KB Output is correct
48 Correct 320 ms 27868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 504 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 7 ms 2140 KB Output is correct
27 Correct 7 ms 1884 KB Output is correct
28 Correct 7 ms 1628 KB Output is correct
29 Correct 11 ms 1628 KB Output is correct
30 Correct 5 ms 1112 KB Output is correct
31 Correct 6 ms 1372 KB Output is correct
32 Correct 6 ms 1116 KB Output is correct
33 Correct 6 ms 1372 KB Output is correct
34 Correct 9 ms 2136 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 4 ms 1372 KB Output is correct
38 Correct 5 ms 1488 KB Output is correct
39 Correct 2 ms 600 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 160 ms 24964 KB Output is correct
51 Correct 134 ms 17484 KB Output is correct
52 Correct 100 ms 21332 KB Output is correct
53 Correct 222 ms 26208 KB Output is correct
54 Correct 153 ms 26012 KB Output is correct
55 Correct 128 ms 25828 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 192 ms 26252 KB Output is correct
62 Correct 218 ms 25448 KB Output is correct
63 Correct 192 ms 19284 KB Output is correct
64 Correct 274 ms 26232 KB Output is correct
65 Correct 160 ms 25940 KB Output is correct
66 Correct 1 ms 344 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 344 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 6 ms 1116 KB Output is correct
71 Correct 1 ms 604 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 265 ms 25544 KB Output is correct
74 Correct 308 ms 24448 KB Output is correct
75 Correct 294 ms 26704 KB Output is correct
76 Correct 402 ms 26704 KB Output is correct
77 Correct 228 ms 26160 KB Output is correct
78 Correct 133 ms 16176 KB Output is correct
79 Correct 6 ms 1372 KB Output is correct
80 Correct 5 ms 1372 KB Output is correct
81 Correct 4 ms 1372 KB Output is correct
82 Correct 7 ms 1372 KB Output is correct
83 Correct 355 ms 28160 KB Output is correct
84 Correct 544 ms 28272 KB Output is correct
85 Correct 402 ms 28244 KB Output is correct
86 Correct 543 ms 28468 KB Output is correct
87 Correct 320 ms 27868 KB Output is correct
88 Correct 780 ms 71252 KB Output is correct
89 Correct 773 ms 52380 KB Output is correct
90 Correct 707 ms 55324 KB Output is correct
91 Correct 732 ms 48208 KB Output is correct
92 Correct 473 ms 35764 KB Output is correct
93 Correct 950 ms 52640 KB Output is correct
94 Correct 840 ms 43084 KB Output is correct
95 Correct 400 ms 39268 KB Output is correct
96 Correct 674 ms 71200 KB Output is correct
97 Correct 159 ms 29084 KB Output is correct
98 Correct 197 ms 41632 KB Output is correct
99 Correct 299 ms 41604 KB Output is correct