Submission #748590

# Submission time Handle Problem Language Result Execution time Memory
748590 2023-05-26T14:16:56 Z GrindMachine Team Contest (JOI22_team) C++17
64 / 100
2000 ms 13784 KB
// Om Namah Shivaya

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a, b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a, b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*

refs:
edi

let's look at the initial array
when will some guy definitely not be in the best triplet?
=> if he dominates in >= 2 areas

so we can remove all guys who cant be there

repeat the process on the resulting array
repeat until we can no longer delete anyone

what does it mean if we can make no more deletions?
there is exactly 1 guy dominating each area

so we can pick the guy dominating each area and that would be our triplet

if < 3 guys are remaining, then not possible

naive simulation of this process = O(n^2)

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

void solve(int test_case)
{
    ll n; cin >> n;
    vector<array<ll,3>> a(n);
    rep(i,n) rep(j,3) cin >> a[i][j];

    while(!a.empty()){
        array<ll,3> best;
        best.fill(0);

        trav(ar,a){
            rep(j,3){
                amax(best[j], ar[j]);
            }
        }

        vector<array<ll,3>> b;

        trav(ar,a){
            ll cnt = 0;
            rep(j,3){
                if(ar[j] == best[j]){
                    cnt++;
                }
            }

            if(cnt <= 1){
                b.pb(ar);
            }
        }

        if(sz(a) == sz(b)){
            ll ans = 0;
            rep(j,3) ans += best[j];
            cout << ans << endl;
            return;
        }

        a = b;
    }

    cout << -1 << endl;
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 19 ms 600 KB Output is correct
28 Correct 32 ms 596 KB Output is correct
29 Correct 40 ms 596 KB Output is correct
30 Correct 14 ms 532 KB Output is correct
31 Correct 15 ms 604 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 63 ms 600 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 27 ms 648 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 34 ms 13096 KB Output is correct
12 Correct 22 ms 7440 KB Output is correct
13 Correct 41 ms 9084 KB Output is correct
14 Correct 33 ms 9180 KB Output is correct
15 Correct 23 ms 3796 KB Output is correct
16 Correct 27 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 34 ms 13096 KB Output is correct
12 Correct 22 ms 7440 KB Output is correct
13 Correct 41 ms 9084 KB Output is correct
14 Correct 33 ms 9180 KB Output is correct
15 Correct 23 ms 3796 KB Output is correct
16 Correct 27 ms 3796 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 34 ms 13512 KB Output is correct
23 Correct 108 ms 13328 KB Output is correct
24 Correct 66 ms 8364 KB Output is correct
25 Correct 57 ms 13208 KB Output is correct
26 Correct 24 ms 3796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 34 ms 13096 KB Output is correct
12 Correct 22 ms 7440 KB Output is correct
13 Correct 41 ms 9084 KB Output is correct
14 Correct 33 ms 9180 KB Output is correct
15 Correct 23 ms 3796 KB Output is correct
16 Correct 27 ms 3796 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 34 ms 13512 KB Output is correct
23 Correct 108 ms 13328 KB Output is correct
24 Correct 66 ms 8364 KB Output is correct
25 Correct 57 ms 13208 KB Output is correct
26 Correct 24 ms 3796 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 6 ms 600 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 36 ms 13128 KB Output is correct
35 Correct 378 ms 12920 KB Output is correct
36 Correct 833 ms 13580 KB Output is correct
37 Correct 375 ms 13468 KB Output is correct
38 Correct 30 ms 3668 KB Output is correct
39 Correct 121 ms 7588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 34 ms 13096 KB Output is correct
12 Correct 22 ms 7440 KB Output is correct
13 Correct 41 ms 9084 KB Output is correct
14 Correct 33 ms 9180 KB Output is correct
15 Correct 23 ms 3796 KB Output is correct
16 Correct 27 ms 3796 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 34 ms 13512 KB Output is correct
23 Correct 108 ms 13328 KB Output is correct
24 Correct 66 ms 8364 KB Output is correct
25 Correct 57 ms 13208 KB Output is correct
26 Correct 24 ms 3796 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 6 ms 600 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 36 ms 13128 KB Output is correct
35 Correct 378 ms 12920 KB Output is correct
36 Correct 833 ms 13580 KB Output is correct
37 Correct 375 ms 13468 KB Output is correct
38 Correct 30 ms 3668 KB Output is correct
39 Correct 121 ms 7588 KB Output is correct
40 Correct 14 ms 536 KB Output is correct
41 Correct 14 ms 600 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 29 ms 624 KB Output is correct
44 Correct 42 ms 10104 KB Output is correct
45 Execution timed out 2083 ms 13784 KB Time limit exceeded
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 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 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 19 ms 600 KB Output is correct
28 Correct 32 ms 596 KB Output is correct
29 Correct 40 ms 596 KB Output is correct
30 Correct 14 ms 532 KB Output is correct
31 Correct 15 ms 604 KB Output is correct
32 Correct 6 ms 600 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 63 ms 600 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 596 KB Output is correct
38 Correct 27 ms 648 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 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 34 ms 13096 KB Output is correct
51 Correct 22 ms 7440 KB Output is correct
52 Correct 41 ms 9084 KB Output is correct
53 Correct 33 ms 9180 KB Output is correct
54 Correct 23 ms 3796 KB Output is correct
55 Correct 27 ms 3796 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 34 ms 13512 KB Output is correct
62 Correct 108 ms 13328 KB Output is correct
63 Correct 66 ms 8364 KB Output is correct
64 Correct 57 ms 13208 KB Output is correct
65 Correct 24 ms 3796 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 0 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 6 ms 600 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 2 ms 340 KB Output is correct
73 Correct 36 ms 13128 KB Output is correct
74 Correct 378 ms 12920 KB Output is correct
75 Correct 833 ms 13580 KB Output is correct
76 Correct 375 ms 13468 KB Output is correct
77 Correct 30 ms 3668 KB Output is correct
78 Correct 121 ms 7588 KB Output is correct
79 Correct 14 ms 536 KB Output is correct
80 Correct 14 ms 600 KB Output is correct
81 Correct 1 ms 596 KB Output is correct
82 Correct 29 ms 624 KB Output is correct
83 Correct 42 ms 10104 KB Output is correct
84 Execution timed out 2083 ms 13784 KB Time limit exceeded
85 Halted 0 ms 0 KB -