Submission #905006

# Submission time Handle Problem Language Result Execution time Memory
905006 2024-01-12T12:50:54 Z Tuanlinh123 Team Contest (JOI22_team) C++17
0 / 100
40 ms 19100 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 4 ms 14936 KB Output is correct
2 Correct 4 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 5 ms 14996 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14936 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 15092 KB Output is correct
15 Incorrect 4 ms 14940 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 5 ms 14996 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14936 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 15092 KB Output is correct
15 Incorrect 4 ms 14940 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14936 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 5 ms 14940 KB Output is correct
9 Correct 5 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 40 ms 19100 KB Output is correct
12 Incorrect 28 ms 17864 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14936 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 5 ms 14940 KB Output is correct
9 Correct 5 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 40 ms 19100 KB Output is correct
12 Incorrect 28 ms 17864 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14936 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 5 ms 14940 KB Output is correct
9 Correct 5 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 40 ms 19100 KB Output is correct
12 Incorrect 28 ms 17864 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14936 KB Output is correct
5 Correct 5 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 4 ms 14940 KB Output is correct
8 Correct 5 ms 14940 KB Output is correct
9 Correct 5 ms 15192 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 40 ms 19100 KB Output is correct
12 Incorrect 28 ms 17864 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 14936 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
4 Correct 4 ms 14940 KB Output is correct
5 Correct 4 ms 14940 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 5 ms 14996 KB Output is correct
8 Correct 3 ms 14940 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 4 ms 14940 KB Output is correct
11 Correct 4 ms 14936 KB Output is correct
12 Correct 5 ms 14940 KB Output is correct
13 Correct 4 ms 14940 KB Output is correct
14 Correct 4 ms 15092 KB Output is correct
15 Incorrect 4 ms 14940 KB Output isn't correct
16 Halted 0 ms 0 KB -