## Submission #582318

# Submission time Handle Problem Language Result Execution time Memory
582318 2022-06-23T16:13:55 Z PoPularPlusPlus Team Contest (JOI22_team) C++17
100 / 100
109 ms 9956 KB
```#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}

//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);

void solve(){
int n;
cin >> n;
vector<pair<int,int>> a , b , c;
int arr[n][3];
for(int i = 0; i < n; i++){
int x , y, z;
cin >> x >> y >> z;
a.pb(mp(x,i));
b.pb(mp(y,i));
c.pb(mp(z,i));
arr[i][0] = x;
arr[i][1] = y;
arr[i][2] = z;
}
sort(all(a),greater<>());
sort(all(b) , greater<>());
sort(all(c), greater<>());
int i = 0 , j = 0 , k = 0;
bool vis[n];
memset(vis,0,sizeof vis);
int cnt = 1;
while(cnt != 0){
cnt = 0;
while(i < (int)a.size() && (arr[a[i].vs][1] == b[j].vf || arr[a[i].vs][2] == c[k].vf)){
vis[a[i].vs] = 1;
while(i < (int)a.size() && vis[a[i].vs])i++;
while(j < (int)b.size() && vis[b[j].vs])j++;
while(k < (int)c.size() && vis[c[k].vs])k++;
cnt=1;
}
while(j < (int)b.size() && (arr[b[j].vs][0] == a[i].vf || arr[b[j].vs][2] == c[k].vf)){
vis[b[j].vs] = 1;
while(i < (int)a.size() && vis[a[i].vs])i++;
while(j < (int)b.size() && vis[b[j].vs])j++;
while(k < (int)c.size() && vis[c[k].vs])k++;
cnt=1;
}
while(k < (int)c.size() && (arr[c[k].vs][1] == b[j].vf || arr[c[k].vs][0] == a[i].vf)){
vis[c[k].vs] = 1;
while(i < (int)a.size() && vis[a[i].vs])i++;
while(j < (int)b.size() && vis[b[j].vs])j++;
while(k < (int)c.size() && vis[c[k].vs])k++;
cnt=1;
}
}
if(i < n && j < n && k < n){
cout << a[i].vf + b[j].vf + c[k].vf << '\n';
}
else cout << -1 << '\n';
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
```

#### Subtask #1 8.0 / 8.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 1 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 1 ms 212 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct

#### Subtask #2 29.0 / 29.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 1 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 1 ms 212 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 3 ms 584 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 3 ms 576 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 540 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 328 KB Output is correct

#### Subtask #3 9.0 / 9.0

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 68 ms 7168 KB Output is correct
12 Correct 53 ms 4772 KB Output is correct
13 Correct 44 ms 5556 KB Output is correct
14 Correct 69 ms 7196 KB Output is correct
15 Correct 61 ms 7136 KB Output is correct
16 Correct 43 ms 7212 KB Output is correct

#### Subtask #4 9.0 / 9.0

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 68 ms 7168 KB Output is correct
12 Correct 53 ms 4772 KB Output is correct
13 Correct 44 ms 5556 KB Output is correct
14 Correct 69 ms 7196 KB Output is correct
15 Correct 61 ms 7136 KB Output is correct
16 Correct 43 ms 7212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 83 ms 7348 KB Output is correct
23 Correct 78 ms 7164 KB Output is correct
24 Correct 61 ms 5056 KB Output is correct
25 Correct 89 ms 7428 KB Output is correct
26 Correct 59 ms 7284 KB Output is correct

#### Subtask #5 9.0 / 9.0

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 68 ms 7168 KB Output is correct
12 Correct 53 ms 4772 KB Output is correct
13 Correct 44 ms 5556 KB Output is correct
14 Correct 69 ms 7196 KB Output is correct
15 Correct 61 ms 7136 KB Output is correct
16 Correct 43 ms 7212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 83 ms 7348 KB Output is correct
23 Correct 78 ms 7164 KB Output is correct
24 Correct 61 ms 5056 KB Output is correct
25 Correct 89 ms 7428 KB Output is correct
26 Correct 59 ms 7284 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 81 ms 7740 KB Output is correct
35 Correct 84 ms 7556 KB Output is correct
36 Correct 83 ms 7844 KB Output is correct
37 Correct 82 ms 7892 KB Output is correct
38 Correct 64 ms 7724 KB Output is correct
39 Correct 37 ms 4684 KB Output is correct

#### Subtask #6 9.0 / 9.0

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 68 ms 7168 KB Output is correct
12 Correct 53 ms 4772 KB Output is correct
13 Correct 44 ms 5556 KB Output is correct
14 Correct 69 ms 7196 KB Output is correct
15 Correct 61 ms 7136 KB Output is correct
16 Correct 43 ms 7212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 83 ms 7348 KB Output is correct
23 Correct 78 ms 7164 KB Output is correct
24 Correct 61 ms 5056 KB Output is correct
25 Correct 89 ms 7428 KB Output is correct
26 Correct 59 ms 7284 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 81 ms 7740 KB Output is correct
35 Correct 84 ms 7556 KB Output is correct
36 Correct 83 ms 7844 KB Output is correct
37 Correct 82 ms 7892 KB Output is correct
38 Correct 64 ms 7724 KB Output is correct
39 Correct 37 ms 4684 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 2 ms 540 KB Output is correct
43 Correct 2 ms 452 KB Output is correct
44 Correct 81 ms 8296 KB Output is correct
45 Correct 82 ms 8268 KB Output is correct
46 Correct 90 ms 8344 KB Output is correct
47 Correct 89 ms 8364 KB Output is correct
48 Correct 67 ms 8168 KB Output is correct

#### Subtask #7 27.0 / 27.0

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 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 1 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 1 ms 212 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 3 ms 584 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 3 ms 596 KB Output is correct
29 Correct 4 ms 596 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 468 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 3 ms 576 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 2 ms 540 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 328 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 68 ms 7168 KB Output is correct
51 Correct 53 ms 4772 KB Output is correct
52 Correct 44 ms 5556 KB Output is correct
53 Correct 69 ms 7196 KB Output is correct
54 Correct 61 ms 7136 KB Output is correct
55 Correct 43 ms 7212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 83 ms 7348 KB Output is correct
62 Correct 78 ms 7164 KB Output is correct
63 Correct 61 ms 5056 KB Output is correct
64 Correct 89 ms 7428 KB Output is correct
65 Correct 59 ms 7284 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 320 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 3 ms 464 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 81 ms 7740 KB Output is correct
74 Correct 84 ms 7556 KB Output is correct
75 Correct 83 ms 7844 KB Output is correct
76 Correct 82 ms 7892 KB Output is correct
77 Correct 64 ms 7724 KB Output is correct
78 Correct 37 ms 4684 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 3 ms 468 KB Output is correct
81 Correct 2 ms 540 KB Output is correct
82 Correct 2 ms 452 KB Output is correct
83 Correct 81 ms 8296 KB Output is correct
84 Correct 82 ms 8268 KB Output is correct
85 Correct 90 ms 8344 KB Output is correct
86 Correct 89 ms 8364 KB Output is correct
87 Correct 67 ms 8168 KB Output is correct
88 Correct 85 ms 9892 KB Output is correct
89 Correct 93 ms 9792 KB Output is correct
90 Correct 109 ms 9912 KB Output is correct
91 Correct 108 ms 9812 KB Output is correct
92 Correct 86 ms 8616 KB Output is correct
93 Correct 90 ms 8996 KB Output is correct
94 Correct 97 ms 8668 KB Output is correct
95 Correct 83 ms 9768 KB Output is correct
96 Correct 95 ms 9876 KB Output is correct
97 Correct 64 ms 9956 KB Output is correct
98 Correct 50 ms 8628 KB Output is correct
99 Correct 81 ms 8728 KB Output is correct