#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int xm[3][n];
vector<vector<pair<int,int>>> x(3,vector<pair<int,int>>(n));
vector<vector<int>> c(n);
vector<int> rem(n,1);
set<pair<int,int>> ck;
vector<int> yk(3);
vector<int> km(3);
for(int i = 0;i < n;++i)
{
cin >> xm[0][i] >> xm[1][i] >> xm[2][i];
x[0][i] = {xm[0][i],i};
x[1][i] = {xm[1][i],i};
x[2][i] = {xm[2][i],i};
}
for(int j =0;j < 3;++j)
{
yk[j] = -1;
sort(x[j].begin(),x[j].end());
for(int u = x[j].size()-1;u >= 0;--u)
{
if(x[j][u].first == x[j].back().first)
{
c[x[j][u].second].push_back(j);
km[j]++;
}
else
{
yk[j] = u;
break;
}
}
}
for(int j = 0;j < n;++j)
{
ck.insert({-int(c[j].size()),j});
}
int ky =n;
while(ck.size())
{
int v = (*ck.begin()).second;
ck.erase(ck.begin());
if(c[v].size() >= 2)
{
ky--;
rem[v] = 0;
for(auto j:c[v])
{
km[j]--;
if(km[j] == 0)
{
int nyk = -1;
for(int u = yk[j];u >= 0;--u)
{
if(rem[x[j][u].second] == 0)
{
continue;
}
if(x[j][u].first == x[j][yk[j]].first)
{
ck.erase({-int(c[x[j][u].second].size()),x[j][u].second});
c[x[j][u].second].push_back(j);
ck.insert({-int(c[x[j][u].second].size()),x[j][u].second});
km[j]++;
}
else
{
nyk = u;
break;
}
}
yk[j] = nyk;
}
}
c[v].clear();
}
else
break;
}
int64_t ans = 0;
for(int i = 0;i < 3;++i)
{
int64_t mx = 0;
for(int j = 0;j < n;++j)
{
mx = max(mx,rem[j] * xm[i][j]);
}
ans += mx;
}
cout << (ans == 0 || ky <= 2 ? -1 : ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
84 ms |
27172 KB |
Output is correct |
12 |
Correct |
82 ms |
17968 KB |
Output is correct |
13 |
Correct |
65 ms |
21608 KB |
Output is correct |
14 |
Correct |
156 ms |
27920 KB |
Output is correct |
15 |
Correct |
90 ms |
31784 KB |
Output is correct |
16 |
Correct |
86 ms |
32980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
84 ms |
27172 KB |
Output is correct |
12 |
Correct |
82 ms |
17968 KB |
Output is correct |
13 |
Correct |
65 ms |
21608 KB |
Output is correct |
14 |
Correct |
156 ms |
27920 KB |
Output is correct |
15 |
Correct |
90 ms |
31784 KB |
Output is correct |
16 |
Correct |
86 ms |
32980 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
92 ms |
26892 KB |
Output is correct |
23 |
Correct |
102 ms |
25436 KB |
Output is correct |
24 |
Correct |
109 ms |
19208 KB |
Output is correct |
25 |
Correct |
179 ms |
26668 KB |
Output is correct |
26 |
Correct |
91 ms |
32040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
84 ms |
27172 KB |
Output is correct |
12 |
Correct |
82 ms |
17968 KB |
Output is correct |
13 |
Correct |
65 ms |
21608 KB |
Output is correct |
14 |
Correct |
156 ms |
27920 KB |
Output is correct |
15 |
Correct |
90 ms |
31784 KB |
Output is correct |
16 |
Correct |
86 ms |
32980 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
92 ms |
26892 KB |
Output is correct |
23 |
Correct |
102 ms |
25436 KB |
Output is correct |
24 |
Correct |
109 ms |
19208 KB |
Output is correct |
25 |
Correct |
179 ms |
26668 KB |
Output is correct |
26 |
Correct |
91 ms |
32040 KB |
Output is correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
416 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
84 ms |
27172 KB |
Output is correct |
12 |
Correct |
82 ms |
17968 KB |
Output is correct |
13 |
Correct |
65 ms |
21608 KB |
Output is correct |
14 |
Correct |
156 ms |
27920 KB |
Output is correct |
15 |
Correct |
90 ms |
31784 KB |
Output is correct |
16 |
Correct |
86 ms |
32980 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
456 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
92 ms |
26892 KB |
Output is correct |
23 |
Correct |
102 ms |
25436 KB |
Output is correct |
24 |
Correct |
109 ms |
19208 KB |
Output is correct |
25 |
Correct |
179 ms |
26668 KB |
Output is correct |
26 |
Correct |
91 ms |
32040 KB |
Output is correct |
27 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |