이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5e4 + 10;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
#define ff first
#define ss second
int n;
iii a[maxn];
vector <iii> d;
map<ii,bool> mp;
int mmin[maxn],mmax[maxn];
ii vval;
void add(iii x)
{
// cout<<"+ "<<x.ff<<' '<<x.ss.ff<<' '<<x.ss.ss<<'\n';
int y = x.ss.ff;
mmax[y]=max(mmax[y],x.ss.ss);
mmin[y]=min(mmin[y],x.ss.ss);
}
int query(iii x)
{
int y=x.ss.ff;
int ans=-1;
if (vval.ff!=-1&&vval.ss>x.ss.ss&&vval.ff>y) ans=max(ans,vval.ff+vval.ss+x.ff);
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i].ff>>a[i].ss.ff>>a[i].ss.ss;
for (int i=0; i<=4000; i++)
mmin[i] = 1e9, mmax[i]=-1e9;
sort(a+1,a+n+1);
d.clear();
int l,r;
int ans=-1;
for (int i=1; i<=n; i++)
{
if (i==1||a[i].ff!=a[i-1].ff) l=i;
if (i==n||a[i].ff!=a[i+1].ff)
{
r=i;
int l2,r2;
vval={-1,-1};
for (int j=4000; j>=1; j--) if (mmin[j]!=1e9&&mmax[j-1]!=-1e9&&mmax[j-1]>mmin[j])
{
vval = {j,mmax[j-1]};
break;
}
// cout<<a[i].ff<<" := "<<vval.ff<<' '<<vval.ss<<'\n';
// for (int j=1; j<=10; j++) cout<<mmin[j]<<','<<mmax[j]<<" "; cout<<'\n';
for (int j=l; j<=r; j++)
{
if (j==l||a[j].ss.ff!=a[j-1].ss.ff) l2=j;
if (j==r||a[j].ss.ff!=a[j+1].ss.ff)
{
r2=j;
ans=max(ans,query(a[l2]));
ans=max(ans,query(a[r2]));
}
}
for (int j=l; j<=r; j++)
{
if (j==l||a[j].ss.ff!=a[j-1].ss.ff) l2=j;
if (j==r||a[j].ss.ff!=a[j+1].ss.ff)
{
r2=j;
add(a[r2]);
add(a[l2]);
}
}
for (int j=1; j<=4000; j++) mmax[j]=max(mmax[j],mmax[j-1]);
}
}
cout<<ans<<'\n';
}
컴파일 시 표준 에러 (stderr) 메시지
team.cpp: In function 'int main()':
team.cpp:47:17: warning: 'l2' may be used uninitialized in this function [-Wmaybe-uninitialized]
47 | int l2,r2;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |