QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543647#17. 文学5un_xiaomivita_msg100 ✓140ms3848kbC++141.9kb2024-09-01 17:45:242024-09-01 17:45:25

Judging History

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

  • [2024-09-01 17:45:25]
  • 评测
  • 测评结果:100
  • 用时:140ms
  • 内存:3848kb
  • [2024-09-01 17:45:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct point {
	double x,y;
	int quad(){
		if(x>0&&y>=0) return 1;
		if(x<=0&&y>0) return 2;
		if(x<0&&y<=0) return 3;
		return 4;
	}
}a[110];
point operator+(point u,point v){return {u.x+v.x,u.y+v.y};}
point operator-(point u,point v){return {u.x-v.x,u.y-v.y};}
double operator^(point u,point v){return u.x*v.y-v.x*u.y;}
bool sortPointAngle(point a,point b){
	if(a.quad()!=b.quad()) return a.quad()<b.quad();
	return (a^b)>0;
}
struct line{
	long long a,b,c,w;
}c[110];
point itsLineLine(line l1,line l2){
	point p;
	double k = l1.a*l2.b-l1.b*l2.a;
	p.x = -(l1.c*l2.b-l1.b*l2.c)/k;
	p.y = -(l1.a*l2.c-l1.c*l2.a)/k;
	return p;
}
bool cov(line i,point j){
	return i.a*j.x+i.b*j.y<=i.c;
}
int main(){
	int n,p;
	cin>>n>>p;
	for(int i=1;i<=n;i++){
		cin>>c[i].a>>c[i].b>>c[i].c>>c[i].w;
	}
	for(int i=1;i<=p;i++){
		cin>>a[i].x>>a[i].y;
	}
	long long ans=1e18;
	for(int i=1;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=p;j++) if(cov(c[i],a[j])) cnt++;
		if(cnt==p) ans=min(ans,c[i].w);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			long long w[p+10][p+10],f[p+10],cnt=0;
			point o=itsLineLine(c[i],c[j]),b[p+10];
			for(int k=1;k<=p;k++){
				if(!cov(c[i],a[k])&&!cov(c[j],a[k])) b[++cnt]=a[k]-o;
			}
			sort(b+1,b+cnt+1,sortPointAngle);
			memset(w,0x3f3f3f3f,sizeof(w));
			memset(f,0x3f3f3f3f,sizeof(f));
			for(int k=1;k<=n;k++)if(k!=i&&k!=j){
				for(int l=1,r;l<=cnt;l++){
					if(!cov(c[k],b[l]+o)) continue;
					for(r=l;r<=cnt&&cov(c[k],b[r+1]+o);r++);
					w[l][r]=min(w[l][r],c[k].w);
					l=r+1;
				}
			}
			for(int d=cnt;d>1;d--){
				for(int l=1,r=d;r<=cnt;l++,r++){
					w[l+1][r]=min(w[l+1][r],w[l][r]);
					w[l][r-1]=min(w[l][r-1],w[l][r]);
				}
			}
			f[0]=0;
			for(int d=1;d<=cnt;d++){
				for(int k=0;k<d;k++){
					f[d]=min(f[d],f[k]+w[k+1][d]);
				}
			}
			ans=min(ans,f[cnt]+c[i].w+c[j].w);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3792kb

input:

8 10
1005 2452 333503 2326
-191 -163 -329185 9988
-636 181 -940525 4582
-16 -150 -122462 5121
128 -1155 -878399 9150
-345 -943 -869354 6220
77 -195 -198041 8231
-22 -27 -41256 3905
-1093 584
407 773
1359 -421
1540 215
-2795 1557
-898 661
1377 406
1587 -2778
1350 428
257 789

output:

21839

result:

ok single line: '21839'

Test #2:

score: 10
Accepted
time: 1ms
memory: 3748kb

input:

16 20
349 -22 -544979 9381
-81 -283 -259442 1339
38 229 -192373 2030
514 680 -909494 4821
-44 -444 -358272 1964
-270 -475 -560390 4498
15 -410 -325830 6911
-117 -103 -203759 3692
277 -918 -807434 1193
-23 -115 -98992 133
16 585 -460625 4903
-298 1051 -894533 2754
-529 2 -798264 5546
75 282 -254073 8...

output:

22556

result:

ok single line: '22556'

Test #3:

score: 10
Accepted
time: 2ms
memory: 3748kb

input:

25 30
5 5 -8930 1
74 343 -296630 1
-7 961 -732920 1
34 32 -60070 1
-96 -50 -158366 1
-231 -275 -423808 1
34 -7 -54656 1
-40 -28 -67756 1
433 -381 -722708 1
-288 251 -492600 1
35 -147 -129983 1
-36 -538 -427702 1
23 -323 -259457 1
-175 588 -534317 1
213 479 -502081 1
83 -3 -132636 1
37 -227 -190323 1...

output:

11

result:

ok single line: '11'

Test #4:

score: 10
Accepted
time: 3ms
memory: 3744kb

input:

33 40
-36 126 -115866 249
-64 -473 -387018 486
-51 -167 -156143 173
1 0 -1 10000
23 -207 -169211 196
-286 546 -612456 339
-25 109 -95792 919
-77 -191 -195517 144
27 -37 -52326 540
28 -118 -104348 738
0 1 -1 10000
144 536 -477472 944
20 -25 -37720 814
-21 -88 -77932 448
574 96 -859490 523
-47 31 -791...

output:

20395

result:

ok single line: '20395'

Test #5:

score: 10
Accepted
time: 17ms
memory: 3764kb

input:

54 60
41 23 -68066 1
34 177 -151398 1
-2 4 -4506 1
-45 -65 -88725 1
1 112 -89468 1
-49 49 -87563 1
-6 -90 -72552 1
27 -260 -211678 1
26 0 -41574 1
18 134 -110856 1
-119 -231 -263711 1
-33 152 -132249 1
62 -6 -99192 1
35 134 -120757 1
-2 -259 -206468 1
2 31 -24974 1
-27 101 -91452 1
-71 -423 -353210 ...

output:

27

result:

ok single line: '27'

Test #6:

score: 10
Accepted
time: 17ms
memory: 3848kb

input:

54 60
-81 84 -145641 2162
98 415 -363143 8110
8 23 -22390 3812
-27 -14 -44597 6576
10 74 -61270 5847
-135 238 -285925 5139
14 -45 -42380 5722
49 42 -85211 5827
-68 -201 -193424 4638
40 83 -92136 6981
17 49 -47660 7512
116 -5 -185042 2873
-15 -5 -24320 9577
64 -155 -160401 4852
94 116 -176228 2481
12...

output:

102597

result:

ok single line: '102597'

Test #7:

score: 10
Accepted
time: 51ms
memory: 3772kb

input:

72 80
-36 -57 -73389 1
-13 -44 -40839 1
22 50 -53238 1
-1 -3 -2873 1
6 -21 -19332 1
-73 124 -152843 1
-41 104 -105781 1
-12 -21 -25485 1
34 43 -64321 1
-110 -89 -189246 1
-7 -11 -14215 1
27 69 -70011 1
15 61 -54312 1
-38 -40 -68652 1
157 -25 -250668 1
-25 1 -39987 1
124 -78 -207168 1
-71 -90 -134254...

output:

33

result:

ok single line: '33'

Test #8:

score: 10
Accepted
time: 55ms
memory: 3792kb

input:

76 80
4 255 -203429 299
-26 128 -110372 9
75 115 -150855 202
-2 2 -3564 306
27 271 -220197 269
279 116 -448441 374
54 206 -185450 674
-7 144 -115609 396
-60 113 -131568 922
-33 -84 -85362 449
-56 88 -113784 671
-19 77 -68633 301
-65 22 -105333 523
-127 145 -232943 56
-59 -40 -99548 353
11 -40 -36495...

output:

20405

result:

ok single line: '20405'

Test #9:

score: 10
Accepted
time: 121ms
memory: 3760kb

input:

91 100
-41 -109 -108949 1
19 -9 -31222 1
-3 18 -15177 1
13 63 -54478 1
1 14 -11291 1
30 -8 -48394 1
14 63 -55097 1
-25 122 -105269 1
29 -67 -70808 1
39 35 -68344 1
56 -161 -156457 1
-45 -1 -71940 1
-9 -67 -55456 1
85 177 -195661 1
-28 -93 -86716 1
2 15 -12364 1
-73 -12 -117014 1
-3 8 -7984 1
227 -19...

output:

38

result:

ok single line: '38'

Test #10:

score: 10
Accepted
time: 140ms
memory: 3736kb

input:

94 100
1 0 -1543 4143
5 67 -54141 9774
-2 8 -7152 4521
34 2 -54386 2437
3 11 -10014 9086
-50 -38 -85504 8201
-22 117 -99854 7588
-30 -19 -50322 7073
1 383 -303921 4705
-76 -143 -166504 6871
-154 -26 -245960 1762
-10 16 -20484 1277
5 1 -8029 251
56 -59 -101157 6913
69 -46 -116196 3672
-56 171 -163141...

output:

149281

result:

ok single line: '149281'