Submission #905009

# Submission time Handle Problem Language Result Execution time Memory
905009 2024-01-12T12:51:50 Z Tuanlinh123 Team Contest (JOI22_team) C++17
100 / 100
297 ms 34896 KB
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
 
const ll maxn=150005;
ll x[maxn], y[maxn], z[maxn], cnt[maxn];
ll cntx[maxn], cnty[maxn], cntz[maxn];
vector <ll> px[maxn], py[maxn], pz[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    vector <ll> nx, ny, nz;
    for (ll i=1; i<=n; i++)
    {
        cin >> x[i] >> y[i] >> z[i];
        nx.pb(x[i]), ny.pb(y[i]), nz.pb(z[i]);
    }
    sort(nx.begin(), nx.end());
    nx.resize(unique(nx.begin(), nx.end())-nx.begin());
    sort(ny.begin(), ny.end());
    ny.resize(unique(ny.begin(), ny.end())-ny.begin());
    sort(nz.begin(), nz.end());
    nz.resize(unique(nz.begin(), nz.end())-nz.begin());
    for (ll i=1; i<=n; i++)
    {
        x[i]=lower_bound(nx.begin(), nx.end(), x[i])-nx.begin()+1;
        y[i]=lower_bound(ny.begin(), ny.end(), y[i])-ny.begin()+1;
        z[i]=lower_bound(nz.begin(), nz.end(), z[i])-nz.begin()+1;
        px[x[i]].pb(i), py[y[i]].pb(i), pz[z[i]].pb(i);
        cntx[x[i]]++, cnty[y[i]]++, cntz[z[i]]++;
    }
    ll mx=nx.size(), my=ny.size(), mz=nz.size();
    for (ll i=1; i<=n; i++)
    {
        cnt[i]=(x[i]==mx)+(y[i]==my)+(z[i]==mz);
        if (cnt[i]>=2) cntx[x[i]]--, cnty[y[i]]--, cntz[z[i]]--;
    }
    while (1)
    {
        bool ok=1;
        if (!cntx[mx] && mx)
        {
            while (!cntx[mx] && mx) mx--;
            for (ll i:px[mx])
            {
                cnt[i]++;
                if (cnt[i]==2)
                {
                    ok=0;
                    cntx[x[i]]--, cnty[y[i]]--, cntz[z[i]]--;
                }
            }
        }
        if (!cnty[my] && my)
        {
            while (!cnty[my] && my) my--;
            for (ll i:py[my])
            {
                cnt[i]++;
                if (cnt[i]==2)
                {
                    ok=0;
                    cntx[x[i]]--, cnty[y[i]]--, cntz[z[i]]--;
                }
            }
        }
        if (!cntz[mz] && mz)
        {
            while (!cntz[mz] && mz) mz--;
            for (ll i:pz[mz])
            {
                cnt[i]++;
                if (cnt[i]==2)
                {
                    ok=0;
                    cntx[x[i]]--, cnty[y[i]]--, cntz[z[i]]--;
                }
            }
        }
        if (ok) break;
    }
    if (mx==0 && my==0 && mz==0) cout << -1;
    else cout << nx[mx-1]+ny[my-1]+nz[mz-1] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14936 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 5 ms 14940 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14936 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 4 ms 14936 KB Output is correct
14 Correct 5 ms 14940 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 5 ms 14940 KB Output is correct
23 Correct 5 ms 14940 KB Output is correct
24 Correct 4 ms 15192 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14936 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 5 ms 14940 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14936 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 4 ms 14936 KB Output is correct
14 Correct 5 ms 14940 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 5 ms 14940 KB Output is correct
23 Correct 5 ms 14940 KB Output is correct
24 Correct 4 ms 15192 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 9 ms 15192 KB Output is correct
27 Correct 7 ms 15196 KB Output is correct
28 Correct 8 ms 15196 KB Output is correct
29 Correct 7 ms 15192 KB Output is correct
30 Correct 6 ms 15196 KB Output is correct
31 Correct 7 ms 14940 KB Output is correct
32 Correct 6 ms 14936 KB Output is correct
33 Correct 5 ms 14940 KB Output is correct
34 Correct 7 ms 15196 KB Output is correct
35 Correct 4 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 7 ms 15196 KB Output is correct
38 Correct 6 ms 15192 KB Output is correct
39 Correct 4 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14940 KB Output is correct
5 Correct 5 ms 14936 KB Output is correct
6 Correct 5 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 14940 KB Output is correct
10 Correct 5 ms 14940 KB Output is correct
11 Correct 41 ms 18912 KB Output is correct
12 Correct 28 ms 17872 KB Output is correct
13 Correct 28 ms 18372 KB Output is correct
14 Correct 42 ms 19652 KB Output is correct
15 Correct 41 ms 19372 KB Output is correct
16 Correct 31 ms 19900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14940 KB Output is correct
5 Correct 5 ms 14936 KB Output is correct
6 Correct 5 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 14940 KB Output is correct
10 Correct 5 ms 14940 KB Output is correct
11 Correct 41 ms 18912 KB Output is correct
12 Correct 28 ms 17872 KB Output is correct
13 Correct 28 ms 18372 KB Output is correct
14 Correct 42 ms 19652 KB Output is correct
15 Correct 41 ms 19372 KB Output is correct
16 Correct 31 ms 19900 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 4 ms 14944 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 50 ms 18980 KB Output is correct
23 Correct 45 ms 18620 KB Output is correct
24 Correct 38 ms 18084 KB Output is correct
25 Correct 50 ms 19388 KB Output is correct
26 Correct 39 ms 19132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14940 KB Output is correct
5 Correct 5 ms 14936 KB Output is correct
6 Correct 5 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 14940 KB Output is correct
10 Correct 5 ms 14940 KB Output is correct
11 Correct 41 ms 18912 KB Output is correct
12 Correct 28 ms 17872 KB Output is correct
13 Correct 28 ms 18372 KB Output is correct
14 Correct 42 ms 19652 KB Output is correct
15 Correct 41 ms 19372 KB Output is correct
16 Correct 31 ms 19900 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 4 ms 14944 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 50 ms 18980 KB Output is correct
23 Correct 45 ms 18620 KB Output is correct
24 Correct 38 ms 18084 KB Output is correct
25 Correct 50 ms 19388 KB Output is correct
26 Correct 39 ms 19132 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 4 ms 14956 KB Output is correct
30 Correct 4 ms 14940 KB Output is correct
31 Correct 6 ms 14936 KB Output is correct
32 Correct 4 ms 14940 KB Output is correct
33 Correct 5 ms 14936 KB Output is correct
34 Correct 66 ms 18868 KB Output is correct
35 Correct 67 ms 19704 KB Output is correct
36 Correct 72 ms 19644 KB Output is correct
37 Correct 70 ms 19384 KB Output is correct
38 Correct 46 ms 19132 KB Output is correct
39 Correct 28 ms 17612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14940 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14940 KB Output is correct
5 Correct 5 ms 14936 KB Output is correct
6 Correct 5 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 5 ms 14940 KB Output is correct
10 Correct 5 ms 14940 KB Output is correct
11 Correct 41 ms 18912 KB Output is correct
12 Correct 28 ms 17872 KB Output is correct
13 Correct 28 ms 18372 KB Output is correct
14 Correct 42 ms 19652 KB Output is correct
15 Correct 41 ms 19372 KB Output is correct
16 Correct 31 ms 19900 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 5 ms 14940 KB Output is correct
19 Correct 4 ms 14940 KB Output is correct
20 Correct 4 ms 14944 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 50 ms 18980 KB Output is correct
23 Correct 45 ms 18620 KB Output is correct
24 Correct 38 ms 18084 KB Output is correct
25 Correct 50 ms 19388 KB Output is correct
26 Correct 39 ms 19132 KB Output is correct
27 Correct 5 ms 14940 KB Output is correct
28 Correct 4 ms 14940 KB Output is correct
29 Correct 4 ms 14956 KB Output is correct
30 Correct 4 ms 14940 KB Output is correct
31 Correct 6 ms 14936 KB Output is correct
32 Correct 4 ms 14940 KB Output is correct
33 Correct 5 ms 14936 KB Output is correct
34 Correct 66 ms 18868 KB Output is correct
35 Correct 67 ms 19704 KB Output is correct
36 Correct 72 ms 19644 KB Output is correct
37 Correct 70 ms 19384 KB Output is correct
38 Correct 46 ms 19132 KB Output is correct
39 Correct 28 ms 17612 KB Output is correct
40 Correct 8 ms 15196 KB Output is correct
41 Correct 6 ms 15072 KB Output is correct
42 Correct 6 ms 15196 KB Output is correct
43 Correct 7 ms 15196 KB Output is correct
44 Correct 94 ms 20152 KB Output is correct
45 Correct 92 ms 19628 KB Output is correct
46 Correct 111 ms 21904 KB Output is correct
47 Correct 95 ms 21696 KB Output is correct
48 Correct 56 ms 21436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 14940 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 5 ms 14936 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 5 ms 14940 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 4 ms 14940 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14936 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 4 ms 14936 KB Output is correct
14 Correct 5 ms 14940 KB Output is correct
15 Correct 4 ms 14940 KB Output is correct
16 Correct 5 ms 14940 KB Output is correct
17 Correct 4 ms 14940 KB Output is correct
18 Correct 4 ms 14940 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
20 Correct 4 ms 14940 KB Output is correct
21 Correct 5 ms 14940 KB Output is correct
22 Correct 5 ms 14940 KB Output is correct
23 Correct 5 ms 14940 KB Output is correct
24 Correct 4 ms 15192 KB Output is correct
25 Correct 5 ms 14940 KB Output is correct
26 Correct 9 ms 15192 KB Output is correct
27 Correct 7 ms 15196 KB Output is correct
28 Correct 8 ms 15196 KB Output is correct
29 Correct 7 ms 15192 KB Output is correct
30 Correct 6 ms 15196 KB Output is correct
31 Correct 7 ms 14940 KB Output is correct
32 Correct 6 ms 14936 KB Output is correct
33 Correct 5 ms 14940 KB Output is correct
34 Correct 7 ms 15196 KB Output is correct
35 Correct 4 ms 14940 KB Output is correct
36 Correct 4 ms 14940 KB Output is correct
37 Correct 7 ms 15196 KB Output is correct
38 Correct 6 ms 15192 KB Output is correct
39 Correct 4 ms 14940 KB Output is correct
40 Correct 4 ms 14940 KB Output is correct
41 Correct 4 ms 14940 KB Output is correct
42 Correct 4 ms 14940 KB Output is correct
43 Correct 5 ms 14940 KB Output is correct
44 Correct 5 ms 14936 KB Output is correct
45 Correct 5 ms 14936 KB Output is correct
46 Correct 4 ms 14936 KB Output is correct
47 Correct 4 ms 14940 KB Output is correct
48 Correct 5 ms 14940 KB Output is correct
49 Correct 5 ms 14940 KB Output is correct
50 Correct 41 ms 18912 KB Output is correct
51 Correct 28 ms 17872 KB Output is correct
52 Correct 28 ms 18372 KB Output is correct
53 Correct 42 ms 19652 KB Output is correct
54 Correct 41 ms 19372 KB Output is correct
55 Correct 31 ms 19900 KB Output is correct
56 Correct 4 ms 14936 KB Output is correct
57 Correct 5 ms 14940 KB Output is correct
58 Correct 4 ms 14940 KB Output is correct
59 Correct 4 ms 14944 KB Output is correct
60 Correct 5 ms 14940 KB Output is correct
61 Correct 50 ms 18980 KB Output is correct
62 Correct 45 ms 18620 KB Output is correct
63 Correct 38 ms 18084 KB Output is correct
64 Correct 50 ms 19388 KB Output is correct
65 Correct 39 ms 19132 KB Output is correct
66 Correct 5 ms 14940 KB Output is correct
67 Correct 4 ms 14940 KB Output is correct
68 Correct 4 ms 14956 KB Output is correct
69 Correct 4 ms 14940 KB Output is correct
70 Correct 6 ms 14936 KB Output is correct
71 Correct 4 ms 14940 KB Output is correct
72 Correct 5 ms 14936 KB Output is correct
73 Correct 66 ms 18868 KB Output is correct
74 Correct 67 ms 19704 KB Output is correct
75 Correct 72 ms 19644 KB Output is correct
76 Correct 70 ms 19384 KB Output is correct
77 Correct 46 ms 19132 KB Output is correct
78 Correct 28 ms 17612 KB Output is correct
79 Correct 8 ms 15196 KB Output is correct
80 Correct 6 ms 15072 KB Output is correct
81 Correct 6 ms 15196 KB Output is correct
82 Correct 7 ms 15196 KB Output is correct
83 Correct 94 ms 20152 KB Output is correct
84 Correct 92 ms 19628 KB Output is correct
85 Correct 111 ms 21904 KB Output is correct
86 Correct 95 ms 21696 KB Output is correct
87 Correct 56 ms 21436 KB Output is correct
88 Correct 243 ms 34744 KB Output is correct
89 Correct 224 ms 28856 KB Output is correct
90 Correct 214 ms 29396 KB Output is correct
91 Correct 184 ms 27324 KB Output is correct
92 Correct 127 ms 23480 KB Output is correct
93 Correct 183 ms 28000 KB Output is correct
94 Correct 193 ms 25020 KB Output is correct
95 Correct 87 ms 25524 KB Output is correct
96 Correct 297 ms 34896 KB Output is correct
97 Correct 53 ms 23740 KB Output is correct
98 Correct 83 ms 24796 KB Output is correct
99 Correct 102 ms 24676 KB Output is correct