QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564150#3224. Directionsdongyc666WA 370ms30300kbC++142.5kb2024-09-14 20:47:592024-09-14 20:48:00

Judging History

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

  • [2024-09-14 20:48:00]
  • 评测
  • 测评结果:WA
  • 用时:370ms
  • 内存:30300kb
  • [2024-09-14 20:47:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int NR=2e5+10;
int n,x[NR],y[NR],w[NR],len,pre[NR],suf[NR],ans=1e18;
struct task{
	int x,y,val,opt;
	bool operator <(const task &T)const{
		return y*T.x<T.y*x; 
	}
}t[NR];
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
map<pii,int>mp;
vector<int>buc;
#define pb emplace_back

void solve(){
	sort(t+1,t+1+len);
	memset(pre,999999,sizeof(pre));
	memset(suf,999999,sizeof(suf));
//	for(int i=1;i<=len;i++)printf("%lld %lld %lld %lld\n",t[i].x,t[i].y,t[i].val,t[i].opt); 
	for(int i=1;i<=len;i++)
		if(t[i].opt==0)pre[i]=min(pre[i-1],t[i].val);
		else pre[i]=pre[i-1];
	for(int i=len;i>=1;i--)
		if(t[i].opt==0)suf[i]=min(suf[i+1],t[i].val);
		else suf[i]=suf[i+1];
	for(int i=1;i<=len;i++)
		if(t[i].opt==1){
			int p1=i-1,p2=i+1;
			if(t[p1].x==t[i].x&&t[p1].y==t[i].y)p1--;
			if(t[p2].x==t[i].x&&t[p2].y==t[i].y)p2++;
//			printf("i:%lld %lld %lld\n",i,p1,p2); 
			ans=min(ans,pre[p1]+suf[p2]+t[i].val);
		}
//	cout<<ans<<endl;
//	puts("-----");
}

signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i]>>w[i];
		if(!x[i]&&!y[i])continue;
		int d=__gcd(x[i],y[i]);d=abs(d);
		x[i]/=d;y[i]/=d;
		if(mp[mkp(x[i],y[i])])mp[mkp(x[i],y[i])]=min(mp[mkp(x[i],y[i])],w[i]);
		else mp[mkp(x[i],y[i])]=w[i];
	}
	len=0;
	for(auto lcy:mp){
		int x=lcy.fi.fi,y=lcy.fi.se,val=lcy.se;
		if(!x){
			if(y>0)y=2e9,x=1;
			else y=-2e9,x=-1;
		}
		if(x<0)t[++len]=task{-x,-y,val,1};
		else t[++len]=task{x,y,val,0};
	}
	solve();
//	cout<<ans<<endl;
	len=0;
	for(auto lcy:mp){
		int x=lcy.fi.fi,y=lcy.fi.se,val=lcy.se;
		if(!x){
			if(y>0)y=2e9,x=1;
			else y=-2e9,x=-1;
		}
		if(x>0)t[++len]=task{x,y,val,1};
		else t[++len]=task{-x,-y,val,0};
	}
	solve();
//	cout<<ans<<endl;
//	len=0;
//	for(auto lcy:mp){
//		int x=lcy.fi.se,y=lcy.fi.fi,val=lcy.se;
//		if(!x){
//			if(y>0)y=2e9,x=1;
//			else y=-2e9,x=-1;
//		}
//		if(x<0)t[++len]=task{-x,y,val,1};
//		else t[++len]=task{x,y,val,0};
//	}
//	solve();
//	len=0;
//	for(auto lcy:mp){
//		int x=lcy.fi.se,y=lcy.fi.fi,val=lcy.se;
//		if(!x){
//			if(y>0)y=2e9,x=-1;
//			else y=-2e9,x=1;
//		}
//		if(x>0)t[++len]=task{x,y,val,1};
//		else t[++len]=task{-x,y,val,0};
//	}
//	solve();
	for(auto lcy:mp){
		int x=lcy.fi.se,y=lcy.fi.fi,val=lcy.se;
		if(mp.count(mkp(-x,-y)))buc.pb(val+mp[mkp(-x,-y)]);
	}
	sort(buc.begin(),buc.end());
	if(buc.size()>2)ans=min(ans,buc[0]+buc[2]);
	if(ans<1e18)cout<<ans<<endl;
	else puts("-1");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 59ms
memory: 12608kb

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: 57ms
memory: 13084kb

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: 93ms
memory: 13444kb

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: 61ms
memory: 12916kb

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: 66ms
memory: 11560kb

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: 97ms
memory: 11696kb

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: 67ms
memory: 12688kb

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: 67ms
memory: 12200kb

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: 95ms
memory: 12288kb

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: 74ms
memory: 12772kb

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: 66ms
memory: 13460kb

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: 107ms
memory: 11532kb

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: 341ms
memory: 30300kb

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: 342ms
memory: 30208kb

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: 370ms
memory: 30160kb

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: 2ms
memory: 11940kb

input:

1
0 0 1

output:

-1

result:

ok single line: '-1'

Test #17:

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

input:

1
1 0 2

output:

-1

result:

ok single line: '-1'

Test #18:

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

input:

1
0 -1 463167712

output:

-1

result:

ok single line: '-1'

Test #19:

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

input:

1
0 -2 1

output:

-1

result:

ok single line: '-1'

Test #20:

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

input:

1
0 -1 2

output:

-1

result:

ok single line: '-1'

Test #21:

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

input:

1
1 0 918809706

output:

-1

result:

ok single line: '-1'

Test #22:

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

input:

1
0 -1 1

output:

-1

result:

ok single line: '-1'

Test #23:

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

input:

1
3 1 1

output:

-1

result:

ok single line: '-1'

Test #24:

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

input:

1
-3 3 104127434

output:

-1

result:

ok single line: '-1'

Test #25:

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

input:

1
-8 5 1

output:

-1

result:

ok single line: '-1'

Test #26:

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

input:

1
5 -9 2

output:

-1

result:

ok single line: '-1'

Test #27:

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

input:

1
-7 7 716743621

output:

-1

result:

ok single line: '-1'

Test #28:

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

input:

1
357462890 848080022 1

output:

-1

result:

ok single line: '-1'

Test #29:

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

input:

1
887520827 -701989688 2

output:

-1

result:

ok single line: '-1'

Test #30:

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

input:

1
-170868300 -940219117 849841157

output:

-1

result:

ok single line: '-1'

Test #31:

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

input:

2
1 0 1
1 0 1

output:

-1

result:

ok single line: '-1'

Test #32:

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

input:

2
-1 -1 2
0 1 2

output:

-1

result:

ok single line: '-1'

Test #33:

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

input:

2
0 0 913090376
-1 -1 541928148

output:

-1

result:

ok single line: '-1'

Test #34:

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

input:

2
-2 1 1
-1 -1 1

output:

-1

result:

ok single line: '-1'

Test #35:

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

input:

2
2 -2 2
2 0 1

output:

-1

result:

ok single line: '-1'

Test #36:

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

input:

2
0 -1 705463868
-2 1 130111370

output:

-1

result:

ok single line: '-1'

Test #37:

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

input:

2
0 -3 1
-3 2 1

output:

-1

result:

ok single line: '-1'

Test #38:

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

input:

2
-3 2 1
3 -2 1

output:

-1

result:

ok single line: '-1'

Test #39:

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

input:

2
2 2 122302093
-2 -2 828026820

output:

-1

result:

ok single line: '-1'

Test #40:

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

input:

2
-5 10 1
-5 2 1

output:

-1

result:

ok single line: '-1'

Test #41:

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

input:

2
1 -5 2
9 5 1

output:

-1

result:

ok single line: '-1'

Test #42:

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

input:

2
-10 -5 31542690
-5 3 129473093

output:

-1

result:

ok single line: '-1'

Test #43:

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

input:

2
266809570 381130972 1
-890632596 454834668 1

output:

-1

result:

ok single line: '-1'

Test #44:

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

input:

2
236002924 544226705 1
-8930666 633728962 1

output:

-1

result:

ok single line: '-1'

Test #45:

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

input:

2
-997831104 237273816 438836317
-754753844 -855592460 577498221

output:

-1

result:

ok single line: '-1'

Test #46:

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

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: 9872kb

input:

3
0 1 1
0 0 1
1 -1 2

output:

-1

result:

ok single line: '-1'

Test #48:

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

input:

3
1 1 364170638
0 1 112013377
-1 0 644196224

output:

-1

result:

ok single line: '-1'

Test #49:

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

input:

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

output:

-1

result:

ok single line: '-1'

Test #50:

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

input:

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

output:

-1

result:

ok single line: '-1'

Test #51:

score: -100
Wrong Answer
time: 1ms
memory: 11788kb

input:

3
1 -1 367635035
0 -1 501995671
1 0 122350696

output:

1359616437

result:

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