Submission #635826

# Submission time Handle Problem Language Result Execution time Memory
635826 2022-08-27T05:51:58 Z Mahdi Team Contest (JOI22_team) C++17
100 / 100
235 ms 10244 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
const int N=15e4+5;
int n, x[N], y[N], z[N];
bool mk[N];

int main(){
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>x[i]>>y[i]>>z[i];
    priority_queue<pii>a, b, c;
    for(int i=0;i<n;++i){
        a.push({x[i], i});
        b.push({y[i], i});
        c.push({z[i], i});
    }
    memset(mk, 1, sizeof(mk));
    while(!a.empty()){
        while(!a.empty() && !mk[a.top().S])
            a.pop();
        while(!b.empty() && !mk[b.top().S])
            b.pop();
        while(!c.empty() && !mk[c.top().S])
            c.pop();
        if(a.empty())
            break;
        int i=a.top().S, j=b.top().S, k=c.top().S;
        if(y[i]==y[j] || z[i]==z[k]){
            mk[i]=0;
            a.pop();
            continue;
        }
        if(x[j]==x[i] || z[j]==z[k]){
            mk[j]=0;
            b.pop();
            continue;
        }
        if(x[k]==x[i] || y[k]==y[j]){
            mk[k]=0;
            c.pop();
            continue;
        }
        cout<<x[i]+y[j]+z[k]<<'\n';
        return 0;
    }
    cout<<-1<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
27 Correct 6 ms 720 KB Output is correct
28 Correct 6 ms 724 KB Output is correct
29 Correct 7 ms 612 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 4 ms 572 KB Output is correct
32 Correct 5 ms 596 KB Output is correct
33 Correct 5 ms 684 KB Output is correct
34 Correct 5 ms 700 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 608 KB Output is correct
38 Correct 4 ms 572 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 72 ms 6288 KB Output is correct
12 Correct 66 ms 4048 KB Output is correct
13 Correct 74 ms 4928 KB Output is correct
14 Correct 124 ms 6276 KB Output is correct
15 Correct 109 ms 7216 KB Output is correct
16 Correct 105 ms 7196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 72 ms 6288 KB Output is correct
12 Correct 66 ms 4048 KB Output is correct
13 Correct 74 ms 4928 KB Output is correct
14 Correct 124 ms 6276 KB Output is correct
15 Correct 109 ms 7216 KB Output is correct
16 Correct 105 ms 7196 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 82 ms 7360 KB Output is correct
23 Correct 88 ms 7196 KB Output is correct
24 Correct 81 ms 5156 KB Output is correct
25 Correct 133 ms 7404 KB Output is correct
26 Correct 116 ms 7204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 72 ms 6288 KB Output is correct
12 Correct 66 ms 4048 KB Output is correct
13 Correct 74 ms 4928 KB Output is correct
14 Correct 124 ms 6276 KB Output is correct
15 Correct 109 ms 7216 KB Output is correct
16 Correct 105 ms 7196 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 82 ms 7360 KB Output is correct
23 Correct 88 ms 7196 KB Output is correct
24 Correct 81 ms 5156 KB Output is correct
25 Correct 133 ms 7404 KB Output is correct
26 Correct 116 ms 7204 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 89 ms 7744 KB Output is correct
35 Correct 105 ms 7592 KB Output is correct
36 Correct 130 ms 7752 KB Output is correct
37 Correct 161 ms 7928 KB Output is correct
38 Correct 135 ms 7812 KB Output is correct
39 Correct 80 ms 4644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 72 ms 6288 KB Output is correct
12 Correct 66 ms 4048 KB Output is correct
13 Correct 74 ms 4928 KB Output is correct
14 Correct 124 ms 6276 KB Output is correct
15 Correct 109 ms 7216 KB Output is correct
16 Correct 105 ms 7196 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 82 ms 7360 KB Output is correct
23 Correct 88 ms 7196 KB Output is correct
24 Correct 81 ms 5156 KB Output is correct
25 Correct 133 ms 7404 KB Output is correct
26 Correct 116 ms 7204 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 5 ms 768 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 89 ms 7744 KB Output is correct
35 Correct 105 ms 7592 KB Output is correct
36 Correct 130 ms 7752 KB Output is correct
37 Correct 161 ms 7928 KB Output is correct
38 Correct 135 ms 7812 KB Output is correct
39 Correct 80 ms 4644 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 4 ms 596 KB Output is correct
42 Correct 3 ms 644 KB Output is correct
43 Correct 4 ms 664 KB Output is correct
44 Correct 110 ms 8356 KB Output is correct
45 Correct 161 ms 8412 KB Output is correct
46 Correct 143 ms 8276 KB Output is correct
47 Correct 181 ms 8460 KB Output is correct
48 Correct 153 ms 8228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 440 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 432 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 5 ms 724 KB Output is correct
27 Correct 6 ms 720 KB Output is correct
28 Correct 6 ms 724 KB Output is correct
29 Correct 7 ms 612 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 4 ms 572 KB Output is correct
32 Correct 5 ms 596 KB Output is correct
33 Correct 5 ms 684 KB Output is correct
34 Correct 5 ms 700 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 608 KB Output is correct
38 Correct 4 ms 572 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 72 ms 6288 KB Output is correct
51 Correct 66 ms 4048 KB Output is correct
52 Correct 74 ms 4928 KB Output is correct
53 Correct 124 ms 6276 KB Output is correct
54 Correct 109 ms 7216 KB Output is correct
55 Correct 105 ms 7196 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 0 ms 468 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 436 KB Output is correct
60 Correct 3 ms 468 KB Output is correct
61 Correct 82 ms 7360 KB Output is correct
62 Correct 88 ms 7196 KB Output is correct
63 Correct 81 ms 5156 KB Output is correct
64 Correct 133 ms 7404 KB Output is correct
65 Correct 116 ms 7204 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 1 ms 468 KB Output is correct
70 Correct 5 ms 768 KB Output is correct
71 Correct 1 ms 468 KB Output is correct
72 Correct 2 ms 468 KB Output is correct
73 Correct 89 ms 7744 KB Output is correct
74 Correct 105 ms 7592 KB Output is correct
75 Correct 130 ms 7752 KB Output is correct
76 Correct 161 ms 7928 KB Output is correct
77 Correct 135 ms 7812 KB Output is correct
78 Correct 80 ms 4644 KB Output is correct
79 Correct 3 ms 596 KB Output is correct
80 Correct 4 ms 596 KB Output is correct
81 Correct 3 ms 644 KB Output is correct
82 Correct 4 ms 664 KB Output is correct
83 Correct 110 ms 8356 KB Output is correct
84 Correct 161 ms 8412 KB Output is correct
85 Correct 143 ms 8276 KB Output is correct
86 Correct 181 ms 8460 KB Output is correct
87 Correct 153 ms 8228 KB Output is correct
88 Correct 161 ms 10124 KB Output is correct
89 Correct 193 ms 10128 KB Output is correct
90 Correct 168 ms 10164 KB Output is correct
91 Correct 235 ms 10164 KB Output is correct
92 Correct 136 ms 8672 KB Output is correct
93 Correct 181 ms 9012 KB Output is correct
94 Correct 189 ms 8872 KB Output is correct
95 Correct 190 ms 10036 KB Output is correct
96 Correct 221 ms 10152 KB Output is correct
97 Correct 200 ms 10244 KB Output is correct
98 Correct 142 ms 8856 KB Output is correct
99 Correct 164 ms 8760 KB Output is correct