#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].push_back({xm[0][i],i});
x[1].push_back({xm[1][i],i});
x[2].push_back({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});
}
while(ck.size())
{
int v = (*ck.begin()).second;
ck.erase(ck.begin());
if(c[v].size() >= 2)
{
rem[v] = 0;
c[v].clear();
for(auto j:c[v])
{
km[j]--;
if(km[j] == 0)
{
int nyk = -1;
for(int u = yk[j];u >= 0;--u)
{
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;
}
}
}
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 ? -1 : ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |