QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#817762 | #3224. Directions | peimuda | WA | 53ms | 17284kb | C++11 | 1.9kb | 2024-12-17 11:42:24 | 2024-12-17 11:42:25 |
Judging History
answer
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define pr pair
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<ll,int>
#define piii pr<pll,ll>
using namespace std;
ll operator*(pll a,pll b)
{
return a.f*b.s-a.s*b.f;
}
ll operator/(pll a,pll b)
{
return a.f*b.f+a.s*b.s;
}
piii p[200005];
piii g[200005];
piii h[200005];
int t,z;
int n;
ll ans=1e18;
bool cmp(piii a,piii b)
{
return a.f*b.f>0;
}
void sol(int x)
{
t=0;
z=0;
ll ki=1e18;
for(int i=0;i<n;i++)
{
if(p[x].f*p[i].f==0)
{
if(p[i].f/p[x].f<0) ki=min(ki,p[i].s);
continue;
}
if(p[x].f*p[i].f>0) g[t++]=p[i];
else h[z++]=p[i];
}
ki+=p[x].s;
sort(g,g+t,cmp);
sort(h,h+z,cmp);
int ct=0;
ll ci=1e18;
for(int i=0;i<t;i++)
{
for(;ct<z;ct++)
{
if(g[i].f*h[ct].f<=0) break;
ci=min(ci,h[ct].s);
}
// cout<<"Fd "<<i<<' '<<ct<<' '<<t<<' '<<z<<" "<<g[i].f.f<<' '<<g[i].f.s<<' '<<h[ct].f.f<<' '<<h[ct].f.s<<endl;
ans=min(ans,p[x].s+g[i].s+ci);
}
// cout<<"F "<<ans<<endl;
ct=0;
for(int i=0;i<t;)
{
ll fi=1e18;
int j=i;
for(;j<t;j++)
{
if(g[i].f*g[j].f!=0) break;
fi=min(fi,g[j].s);
}
ll oi=1e18;
for(;ct<z;ct++) if(g[i].f*h[ct].f<=0) break;
for(;ct<z;ct++)
{
if(g[i].f*h[ct].f<0) break;
oi=min(oi,g[ct].s);
}
// cout<<"Og "<<ki<<' '<<fi<<' '<<oi<<endl;
ans=min(ans,ki+fi+oi);
ki=min(ki,fi+oi);
i=j;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin>>n;
pii mi=mp(2000000000,0);
for(int i=0;i<n;i++)
{
cin>>p[i].f.f>>p[i].f.s>>p[i].s;
if(p[i].f.f==0&&p[i].f.s==0)
{
i--;
n--;
continue;
}
mi=min(mi,mp(p[i].s,i));
}
if(n==0)
{
cout<<"-1\n";
return 0;
}
sol(mi.s);
pii gi=mp(2000000000,0);
for(int i=0;i<n;i++) if(p[i].f*p[mi.s].f==0)
{
if(p[i].f/p[mi.s].f<0) gi=min(gi,mp(p[i].s,i));
}
sol(gi.s);
if(ans<1e15) cout<<ans<<endl;
else cout<<"-1\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 39ms
memory: 17284kb
input:
200000 -1 -1 1 1 1 1 0 1 1 1 0 1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 -1 1 0 1 1 0 0 1 0 0 1 1 -1 1 -1 -1 1 0 0 1 1 0 1 -1 1 1 -1 1 1 1 1 1 1 1 1 -1 1 1 0 -1 1 1 -1 1 -1 0 1 1 0 1 1 -1 1 0 -1 1 1 0 1 -1 1 1 1 0 1 -1 0 1 1 1 1 1 0 1 -1 -1 1 -1 1 1 -1 -1 1 0 -1 1 0 -1 1 1 1 1 1 -1 1 0 1 1 1 1 1 -1 1 1 1 -1 1 0...
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 44ms
memory: 14724kb
input:
200000 -1 -1 2 1 0 1 1 0 2 1 -1 2 1 0 1 -1 1 1 -1 -1 2 1 1 1 0 -1 2 -1 -1 1 0 1 2 0 -1 2 -1 0 2 0 0 2 -1 1 1 1 1 1 -1 0 1 1 -1 2 1 0 1 0 0 1 1 0 2 0 -1 1 0 1 1 0 -1 2 -1 1 2 0 1 2 -1 1 2 0 1 1 0 1 1 1 1 2 1 1 1 1 0 2 1 1 2 -1 1 2 -1 1 1 0 1 2 0 -1 2 1 0 2 0 1 1 0 -1 1 1 -1 1 1 0 2 0 -1 1 -1 0 1 0 -1...
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 53ms
memory: 13120kb
input:
200000 1 0 555860533 -1 1 633479355 0 0 411890838 -1 -1 411764668 0 0 324117889 1 1 147426106 1 0 41681213 1 -1 169580394 1 -1 204074237 -1 1 265787176 1 -1 204010614 0 -1 582574240 0 -1 98238758 1 1 489573021 -1 1 747647275 1 -1 933893240 0 -1 663924164 0 0 470849190 1 -1 479419247 -1 -1 53695974 0...
output:
81775
result:
wrong answer 1st lines differ - expected: '95355', found: '81775'