QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#849405#3224. DirectionsCarroT1212WA 155ms38464kbC++142.0kb2025-01-09 15:12:152025-01-09 15:12:20

Judging History

你现在查看的是最新测评结果

  • [2025-01-09 15:12:20]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:38464kb
  • [2025-01-09 15:12:15]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=2e5+7;
const ld pi=acos(-1),eps=1e-7;
ll n,m,ans=J;
pair<ld,ll> a[N],b[N],c[N];
map<ld,ll> mp;
ld tur(ld x) { return x+(x>0?-pi:pi); }
void go(ll p) {
	if (b[p].fi>0) for (ll i=1;i<=m;i++) b[i].fi=tur(b[i].fi);
	for (ll i=1;i<=m;i++) c[i]=b[i];
	sort(c+1,c+m+1);
	ld l=b[p].fi,r=l+pi;
	ll s=0,t=1,mnn=J;
	for (ll i=1;i<=m;i++) if (c[i].fi>l+eps) { s=i; break; }
	for (ll i=1;i<=m;i++) if (c[i].fi>r+eps) { t=i; break; }
	if (!s) return;
	// printf("%lld %lld %lld %Lf %Lf\n",p,s,t,l,r);
	// for (ll i=1;i<=m;i++) printf(" %Lf %lld\n",c[i].fi,c[i].se);
	for (ll i=s,u=t;c[i].fi<r&&i<=m;i++) {
		while (c[u].fi!=l) {
			if (c[i].fi<=0?c[u].fi-c[i].fi<pi:c[u].fi>0||c[i].fi-c[u].fi>pi)
				mnn=min(mnn,c[u].se),u=u%m+1;
			else break;
		}
		ans=min(ans,b[p].se+mnn+c[i].se);
		// printf(" %lld %lld %lld %lld %lld\n",i,u,b[p].se,mnn,c[i].se);
	}
}
void solve3() {
	ll mn=J,p=0,pp=0;
	for (ll i=1;i<=m;i++) if (b[i].se<mn) mn=b[i].se,p=i;
	pp=mp[tur(b[p].fi)];
	go(p);
	if (pp) go(pp);
}
void solve4() {
	vector<ll> v;
	for (auto i:mp) if (i.fi>0&&mp.count(tur(i.fi))) v.pb(b[i.se].se+b[mp[tur(i.fi)]].se);
	sort(v.begin(),v.end());
	if (v.size()>=2) ans=min(ans,v[0]+v[1]);
}
void mian() {
	scanf("%lld",&n);
	for (ll i=1,x,y,z;i<=n;i++) {
		scanf("%lld%lld%lld",&x,&y,&z);
		if (!x&&!y) z=J;
		a[i]={atan2(y,x),z};
	}
	sort(a+1,a+n+1);
	for (ll l=1,r;l<=n;l=r+1) {
		for (r=l;r<n&&a[r+1].fi==a[l].fi;r++);
		b[++m]={a[l].fi,J};
		for (ll i=l;i<=r;i++) b[m].se=min(b[m].se,a[i].se);
		mp[b[m].fi]=m;
	}
	if (m<3) return cout<<"-1",void();
	// for (ll i=1;i<=m;i++) printf(" %Lf %lld\n",b[i].fi,b[i].se);
	solve4(),solve3();
	cout<<(ans==J?-1:ans);
}
bool ORY; int main() {
	// while (1)
	// int t; for (scanf("%d",&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 44ms
memory: 12560kb

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: 45ms
memory: 14356kb

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: 0
Accepted
time: 52ms
memory: 13228kb

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:

95355

result:

ok single line: '95355'

Test #4:

score: 0
Accepted
time: 45ms
memory: 13040kb

input:

200000
-1 0 1
-2 2 1
0 0 1
1 1 1
2 -2 1
0 2 1
-1 -1 1
0 0 1
1 1 1
2 1 1
0 1 1
-2 -1 1
-1 -1 1
-2 2 1
-1 -2 1
0 0 1
-2 0 1
2 1 1
1 -2 1
1 -2 1
-1 -2 1
0 1 1
0 -1 1
1 -2 1
0 1 1
2 0 1
-1 1 1
1 0 1
2 -2 1
-1 2 1
-2 1 1
-1 0 1
2 1 1
0 1 1
-1 -1 1
0 2 1
2 2 1
2 -2 1
1 -2 1
-2 0 1
-2 -2 1
-2 1 1
1 2 1
2 -...

output:

3

result:

ok single line: '3'

Test #5:

score: 0
Accepted
time: 42ms
memory: 13676kb

input:

200000
-2 1 2
2 1 2
1 -1 2
1 2 2
-1 2 1
1 -1 2
1 -1 2
-2 -1 2
1 2 1
2 -1 2
0 1 2
1 -1 1
-2 2 1
-2 1 2
-1 0 2
2 0 1
1 -2 2
-1 1 1
1 -2 1
-2 1 2
-1 1 2
2 -2 1
-2 1 2
-2 1 1
-2 2 1
0 -2 1
2 -2 2
0 2 2
2 2 2
2 2 2
0 2 2
-2 2 2
1 -2 1
1 0 2
-1 -2 1
-2 1 2
0 -1 1
2 0 1
-1 -1 2
1 -2 1
-2 -2 1
1 -1 2
-2 2 1...

output:

3

result:

ok single line: '3'

Test #6:

score: 0
Accepted
time: 59ms
memory: 13460kb

input:

200000
-1 -2 29368112
2 -1 24391896
0 -2 58495223
0 1 266081519
-2 -2 381375524
2 1 738559870
2 -2 407460939
-1 1 562555301
-2 2 185971753
2 -1 886154605
1 1 842679105
1 0 300033644
2 1 430527773
-1 -1 295205658
-1 2 903654949
-2 2 674980542
2 -2 725974565
0 1 924537846
-2 1 828956777
0 2 145229295
...

output:

50007

result:

ok single line: '50007'

Test #7:

score: 0
Accepted
time: 46ms
memory: 13732kb

input:

200000
-1 1 1
2 0 1
-2 2 1
-2 -2 1
-1 -1 1
1 0 1
1 -1 1
1 -1 1
2 0 1
2 -2 1
-3 -1 1
-1 3 1
0 0 1
2 3 1
-2 -1 1
3 0 1
-1 -3 1
-1 -1 1
-3 1 1
-1 0 1
-1 -3 1
-1 0 1
2 3 1
-3 3 1
-1 2 1
-3 0 1
3 2 1
-2 1 1
-2 -2 1
2 3 1
2 3 1
-3 -3 1
2 3 1
1 -1 1
-1 -2 1
1 1 1
-3 1 1
-2 0 1
-1 -3 1
1 -2 1
-2 0 1
1 -1 1
...

output:

3

result:

ok single line: '3'

Test #8:

score: 0
Accepted
time: 47ms
memory: 13236kb

input:

200000
-1 3 2
-2 -2 2
1 -3 2
3 0 2
3 -3 1
2 1 1
-1 -3 2
0 0 2
1 0 2
1 0 1
-1 -1 2
1 2 2
-1 1 2
0 2 1
0 3 2
3 0 2
-1 -2 1
-3 -2 2
0 0 1
-3 -2 2
3 1 2
3 0 1
-2 2 1
-1 0 2
3 3 1
0 3 2
1 -1 1
-2 0 1
1 -1 2
2 3 2
-3 -3 1
2 0 2
0 -2 2
3 0 1
3 -2 2
-1 2 1
-1 0 2
1 2 1
2 1 1
1 -1 2
1 -1 1
-2 -1 2
0 -3 2
-1 ...

output:

3

result:

ok single line: '3'

Test #9:

score: 0
Accepted
time: 61ms
memory: 14368kb

input:

200000
1 -3 518137122
2 0 834424887
-3 -2 231423111
1 -2 504370653
0 -1 410088110
1 -3 604634228
0 -1 778458743
-2 0 372225547
-3 -3 213186092
-1 3 217495508
-1 0 897781531
-1 3 890144466
0 0 174193369
2 -2 392192299
3 -3 664301085
-1 2 394866190
3 -2 923710269
-1 -1 601337929
1 -3 519383120
0 -1 18...

output:

55780

result:

ok single line: '55780'

Test #10:

score: 0
Accepted
time: 46ms
memory: 12408kb

input:

200000
-6 7 1
1 -5 1
-5 -5 1
-1 3 1
-4 5 1
9 0 1
-2 -10 1
6 9 1
9 8 1
8 -3 1
0 3 1
-7 -7 1
1 9 1
3 -3 1
-5 -6 1
-9 5 1
-9 0 1
8 8 1
-2 -9 1
0 8 1
-10 2 1
1 -5 1
6 -7 1
4 3 1
4 -6 1
-9 10 1
-2 -1 1
9 8 1
-8 7 1
3 -6 1
0 10 1
0 10 1
-10 6 1
3 -9 1
8 -10 1
-5 6 1
-1 6 1
0 2 1
-1 -5 1
6 8 1
1 -9 1
8 4 1...

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 52ms
memory: 13564kb

input:

200000
6 -8 2
-5 9 2
0 -4 2
-2 -9 1
7 8 2
10 8 2
-5 5 2
4 3 1
-8 -7 2
-1 0 1
-2 -3 1
-9 -6 1
10 7 2
1 -8 2
-3 -4 2
-8 9 1
5 -3 2
-10 -5 2
-8 10 2
2 -7 2
7 -8 1
-9 -1 2
-4 6 2
-2 10 2
3 0 1
-7 2 1
-2 10 2
9 4 2
-9 9 2
9 -5 1
4 -4 1
8 2 1
-1 8 1
6 -9 2
-1 7 1
-8 7 1
-6 7 1
-6 -4 1
4 8 1
-9 8 2
-7 -8 1...

output:

3

result:

ok single line: '3'

Test #12:

score: 0
Accepted
time: 59ms
memory: 14176kb

input:

200000
1 -9 868328714
1 -2 169338841
2 -3 522935877
7 4 846334853
6 3 95747102
2 8 683463453
-3 10 674070722
7 5 879124379
9 7 411799557
-6 5 452823389
10 0 460945667
-5 -10 384988883
-4 10 944711005
-8 -6 540403661
6 0 804621844
-5 9 121613673
10 -3 854883852
7 -5 776415902
0 9 555825703
-6 -5 2637...

output:

49548

result:

ok single line: '49548'

Test #13:

score: 0
Accepted
time: 103ms
memory: 38464kb

input:

200000
-712994576 681957216 1
742214757 -749366118 1
643431902 -900788690 1
490499102 469176533 1
274934881 224980485 1
66532381 -860911586 1
776002355 -154470536 1
837312330 -571543374 1
971536663 -630853477 1
116903881 442223660 1
667716471 -828182152 1
336272958 -251409255 1
503068146 763971728 1...

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 135ms
memory: 38432kb

input:

200000
-602008984 693387889 1
897189880 -803134494 1
35887395 374199573 1
97436871 -310842124 2
-317640064 -574779803 1
-295972377 43817547 2
340192254 370024590 1
-78314559 -497366938 2
664758677 345537889 2
-631188522 -421590323 2
916801468 87978323 2
-392373838 89334600 1
993337752 798186512 2
-6...

output:

3

result:

ok single line: '3'

Test #15:

score: 0
Accepted
time: 155ms
memory: 38240kb

input:

200000
624731001 -756312895 732418025
-723028405 454048115 884229821
657008140 -126241037 451702065
-299325474 365545215 62086888
694524222 901018738 927667060
-806668501 548329101 564050553
162465309 -226915270 370979883
357761925 4184566 129493846
718751910 -547636756 397742261
-413240751 -9747541...

output:

31001

result:

ok single line: '31001'

Test #16:

score: 0
Accepted
time: 0ms
memory: 7748kb

input:

1
0 0 1

output:

-1

result:

ok single line: '-1'

Test #17:

score: 0
Accepted
time: 2ms
memory: 7848kb

input:

1
1 0 2

output:

-1

result:

ok single line: '-1'

Test #18:

score: 0
Accepted
time: 0ms
memory: 8128kb

input:

1
0 -1 463167712

output:

-1

result:

ok single line: '-1'

Test #19:

score: 0
Accepted
time: 2ms
memory: 8044kb

input:

1
0 -2 1

output:

-1

result:

ok single line: '-1'

Test #20:

score: 0
Accepted
time: 1ms
memory: 7912kb

input:

1
0 -1 2

output:

-1

result:

ok single line: '-1'

Test #21:

score: 0
Accepted
time: 0ms
memory: 7832kb

input:

1
1 0 918809706

output:

-1

result:

ok single line: '-1'

Test #22:

score: 0
Accepted
time: 1ms
memory: 7916kb

input:

1
0 -1 1

output:

-1

result:

ok single line: '-1'

Test #23:

score: 0
Accepted
time: 0ms
memory: 8176kb

input:

1
3 1 1

output:

-1

result:

ok single line: '-1'

Test #24:

score: 0
Accepted
time: 2ms
memory: 8364kb

input:

1
-3 3 104127434

output:

-1

result:

ok single line: '-1'

Test #25:

score: 0
Accepted
time: 1ms
memory: 8188kb

input:

1
-8 5 1

output:

-1

result:

ok single line: '-1'

Test #26:

score: 0
Accepted
time: 0ms
memory: 8168kb

input:

1
5 -9 2

output:

-1

result:

ok single line: '-1'

Test #27:

score: 0
Accepted
time: 1ms
memory: 8172kb

input:

1
-7 7 716743621

output:

-1

result:

ok single line: '-1'

Test #28:

score: 0
Accepted
time: 0ms
memory: 8000kb

input:

1
357462890 848080022 1

output:

-1

result:

ok single line: '-1'

Test #29:

score: 0
Accepted
time: 0ms
memory: 8204kb

input:

1
887520827 -701989688 2

output:

-1

result:

ok single line: '-1'

Test #30:

score: 0
Accepted
time: 2ms
memory: 8416kb

input:

1
-170868300 -940219117 849841157

output:

-1

result:

ok single line: '-1'

Test #31:

score: 0
Accepted
time: 2ms
memory: 7916kb

input:

2
1 0 1
1 0 1

output:

-1

result:

ok single line: '-1'

Test #32:

score: 0
Accepted
time: 2ms
memory: 7960kb

input:

2
-1 -1 2
0 1 2

output:

-1

result:

ok single line: '-1'

Test #33:

score: 0
Accepted
time: 0ms
memory: 7996kb

input:

2
0 0 913090376
-1 -1 541928148

output:

-1

result:

ok single line: '-1'

Test #34:

score: 0
Accepted
time: 2ms
memory: 8416kb

input:

2
-2 1 1
-1 -1 1

output:

-1

result:

ok single line: '-1'

Test #35:

score: 0
Accepted
time: 0ms
memory: 8000kb

input:

2
2 -2 2
2 0 1

output:

-1

result:

ok single line: '-1'

Test #36:

score: 0
Accepted
time: 0ms
memory: 8092kb

input:

2
0 -1 705463868
-2 1 130111370

output:

-1

result:

ok single line: '-1'

Test #37:

score: 0
Accepted
time: 2ms
memory: 8412kb

input:

2
0 -3 1
-3 2 1

output:

-1

result:

ok single line: '-1'

Test #38:

score: 0
Accepted
time: 2ms
memory: 8096kb

input:

2
-3 2 1
3 -2 1

output:

-1

result:

ok single line: '-1'

Test #39:

score: 0
Accepted
time: 1ms
memory: 8000kb

input:

2
2 2 122302093
-2 -2 828026820

output:

-1

result:

ok single line: '-1'

Test #40:

score: 0
Accepted
time: 0ms
memory: 8420kb

input:

2
-5 10 1
-5 2 1

output:

-1

result:

ok single line: '-1'

Test #41:

score: 0
Accepted
time: 2ms
memory: 8284kb

input:

2
1 -5 2
9 5 1

output:

-1

result:

ok single line: '-1'

Test #42:

score: 0
Accepted
time: 2ms
memory: 8088kb

input:

2
-10 -5 31542690
-5 3 129473093

output:

-1

result:

ok single line: '-1'

Test #43:

score: 0
Accepted
time: 1ms
memory: 8100kb

input:

2
266809570 381130972 1
-890632596 454834668 1

output:

-1

result:

ok single line: '-1'

Test #44:

score: 0
Accepted
time: 1ms
memory: 8104kb

input:

2
236002924 544226705 1
-8930666 633728962 1

output:

-1

result:

ok single line: '-1'

Test #45:

score: 0
Accepted
time: 0ms
memory: 8272kb

input:

2
-997831104 237273816 438836317
-754753844 -855592460 577498221

output:

-1

result:

ok single line: '-1'

Test #46:

score: 0
Accepted
time: 0ms
memory: 8196kb

input:

3
1 -1 1
-1 -1 1
0 1 1

output:

3

result:

ok single line: '3'

Test #47:

score: 0
Accepted
time: 1ms
memory: 8284kb

input:

3
0 1 1
0 0 1
1 -1 2

output:

-1

result:

ok single line: '-1'

Test #48:

score: -100
Wrong Answer
time: 0ms
memory: 8172kb

input:

3
1 1 364170638
0 1 112013377
-1 0 644196224

output:

1120380239

result:

wrong answer 1st lines differ - expected: '-1', found: '1120380239'