Submission #555505

# Submission time Handle Problem Language Result Execution time Memory
555505 2022-05-01T06:19:34 Z AriaH Team Contest (JOI22_team) C++17
100 / 100
443 ms 27048 KB
/* Im the best and i work like that */

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#define F first
#define S second
#define all(x) x.begin(),x.end()
#define Mp make_pair
#define point complex
#define endl '\n'
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file_io freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define mashtali return cout << "Hello, World!", 0;

const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;
const double pi = acos(-1);
const ld eps = 1e-18;
const ld one = 1.;

ll pw(ll a, ll b, ll M, ll ret = 1) { if(a == 0) return 0; a %= M; while(b) { ret = (b & 1? ret * a % M : ret), a = a * a % M, b >>= 1; } return ret % M; }

mt19937 rng(time(nullptr));

int n, A[N], B[N], C[N];

int main()
{
	fast_io;
    set < pii > a, b, c;
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> A[i] >> B[i] >> C[i];
        a.insert(Mp(-A[i], i));
        b.insert(Mp(-B[i], i));
        c.insert(Mp(-C[i], i));
    }
    while(SZ(a))
    {
        pii aa = *a.begin();
        pii bb = *b.begin();
        pii cc = *c.begin();
        aa.F *= -1;
        bb.F *= -1;
        cc.F *= -1;
        ///cout << aa.F << " " << bb.F << " " << cc.F << endl;
        int id = aa.S;
        if(B[id] >= bb.F || C[aa.S] >= cc.F)
        {
            a.erase(Mp(-A[id], id));
            b.erase(Mp(-B[id], id));
            c.erase(Mp(-C[id], id));
            continue;
        }
        id = bb.S;
        if(A[id] >= aa.F || C[id] >= cc.F)
        {
            a.erase(Mp(-A[id], id));
            b.erase(Mp(-B[id], id));
            c.erase(Mp(-C[id], id));
            continue;
        }
        id = cc.S;
        if(A[id] >= aa.F || B[id] >= bb.F)
        {
            a.erase(Mp(-A[id], id));
            b.erase(Mp(-B[id], id));
            c.erase(Mp(-C[id], id));
            continue;
        }
        cout << aa.F + bb.F + cc.F << endl;
        return 0;
    }
    cout << -1 << endl;
	return 0;
}

/* check corner case(n = 1?), watch for negetive index or overflow */
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 7 ms 944 KB Output is correct
27 Correct 5 ms 976 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 6 ms 980 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 4 ms 884 KB Output is correct
32 Correct 6 ms 956 KB Output is correct
33 Correct 5 ms 980 KB Output is correct
34 Correct 5 ms 972 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 900 KB Output is correct
38 Correct 5 ms 980 KB Output is correct
39 Correct 2 ms 596 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 193 ms 23728 KB Output is correct
12 Correct 137 ms 16032 KB Output is correct
13 Correct 114 ms 19792 KB Output is correct
14 Correct 210 ms 23976 KB Output is correct
15 Correct 156 ms 23672 KB Output is correct
16 Correct 152 ms 23748 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 193 ms 23728 KB Output is correct
12 Correct 137 ms 16032 KB Output is correct
13 Correct 114 ms 19792 KB Output is correct
14 Correct 210 ms 23976 KB Output is correct
15 Correct 156 ms 23672 KB Output is correct
16 Correct 152 ms 23748 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 197 ms 24056 KB Output is correct
23 Correct 208 ms 23512 KB Output is correct
24 Correct 176 ms 17500 KB Output is correct
25 Correct 278 ms 24232 KB Output is correct
26 Correct 167 ms 24216 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 193 ms 23728 KB Output is correct
12 Correct 137 ms 16032 KB Output is correct
13 Correct 114 ms 19792 KB Output is correct
14 Correct 210 ms 23976 KB Output is correct
15 Correct 156 ms 23672 KB Output is correct
16 Correct 152 ms 23748 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 197 ms 24056 KB Output is correct
23 Correct 208 ms 23512 KB Output is correct
24 Correct 176 ms 17500 KB Output is correct
25 Correct 278 ms 24232 KB Output is correct
26 Correct 167 ms 24216 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 6 ms 992 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 251 ms 23360 KB Output is correct
35 Correct 276 ms 21964 KB Output is correct
36 Correct 317 ms 24296 KB Output is correct
37 Correct 355 ms 24760 KB Output is correct
38 Correct 206 ms 23792 KB Output is correct
39 Correct 103 ms 14668 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 193 ms 23728 KB Output is correct
12 Correct 137 ms 16032 KB Output is correct
13 Correct 114 ms 19792 KB Output is correct
14 Correct 210 ms 23976 KB Output is correct
15 Correct 156 ms 23672 KB Output is correct
16 Correct 152 ms 23748 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 596 KB Output is correct
22 Correct 197 ms 24056 KB Output is correct
23 Correct 208 ms 23512 KB Output is correct
24 Correct 176 ms 17500 KB Output is correct
25 Correct 278 ms 24232 KB Output is correct
26 Correct 167 ms 24216 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 6 ms 992 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 251 ms 23360 KB Output is correct
35 Correct 276 ms 21964 KB Output is correct
36 Correct 317 ms 24296 KB Output is correct
37 Correct 355 ms 24760 KB Output is correct
38 Correct 206 ms 23792 KB Output is correct
39 Correct 103 ms 14668 KB Output is correct
40 Correct 3 ms 724 KB Output is correct
41 Correct 4 ms 980 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 4 ms 980 KB Output is correct
44 Correct 338 ms 25132 KB Output is correct
45 Correct 443 ms 25248 KB Output is correct
46 Correct 419 ms 24780 KB Output is correct
47 Correct 430 ms 25328 KB Output is correct
48 Correct 252 ms 25304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 7 ms 944 KB Output is correct
27 Correct 5 ms 976 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 6 ms 980 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 4 ms 884 KB Output is correct
32 Correct 6 ms 956 KB Output is correct
33 Correct 5 ms 980 KB Output is correct
34 Correct 5 ms 972 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 3 ms 900 KB Output is correct
38 Correct 5 ms 980 KB Output is correct
39 Correct 2 ms 596 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 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 193 ms 23728 KB Output is correct
51 Correct 137 ms 16032 KB Output is correct
52 Correct 114 ms 19792 KB Output is correct
53 Correct 210 ms 23976 KB Output is correct
54 Correct 156 ms 23672 KB Output is correct
55 Correct 152 ms 23748 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 596 KB Output is correct
61 Correct 197 ms 24056 KB Output is correct
62 Correct 208 ms 23512 KB Output is correct
63 Correct 176 ms 17500 KB Output is correct
64 Correct 278 ms 24232 KB Output is correct
65 Correct 167 ms 24216 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 6 ms 992 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 251 ms 23360 KB Output is correct
74 Correct 276 ms 21964 KB Output is correct
75 Correct 317 ms 24296 KB Output is correct
76 Correct 355 ms 24760 KB Output is correct
77 Correct 206 ms 23792 KB Output is correct
78 Correct 103 ms 14668 KB Output is correct
79 Correct 3 ms 724 KB Output is correct
80 Correct 4 ms 980 KB Output is correct
81 Correct 4 ms 980 KB Output is correct
82 Correct 4 ms 980 KB Output is correct
83 Correct 338 ms 25132 KB Output is correct
84 Correct 443 ms 25248 KB Output is correct
85 Correct 419 ms 24780 KB Output is correct
86 Correct 430 ms 25328 KB Output is correct
87 Correct 252 ms 25304 KB Output is correct
88 Correct 328 ms 25888 KB Output is correct
89 Correct 372 ms 25292 KB Output is correct
90 Correct 332 ms 27048 KB Output is correct
91 Correct 388 ms 24812 KB Output is correct
92 Correct 372 ms 24876 KB Output is correct
93 Correct 394 ms 26084 KB Output is correct
94 Correct 442 ms 25828 KB Output is correct
95 Correct 266 ms 26968 KB Output is correct
96 Correct 214 ms 26912 KB Output is correct
97 Correct 169 ms 25732 KB Output is correct
98 Correct 150 ms 25696 KB Output is correct
99 Correct 151 ms 25652 KB Output is correct