QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#554072#2750. Collusion on Two WheelsTenshi#AC ✓1296ms3772kbC++201.8kb2024-09-09 04:43:132024-09-09 04:43:13

Judging History

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

  • [2024-09-09 04:43:13]
  • 评测
  • 测评结果:AC
  • 用时:1296ms
  • 内存:3772kb
  • [2024-09-09 04:43:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
 
inline void read(int &x){
    int s=0; x=1;
    char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

const int N=1010;

int n;
pii w[N];

int cal(vector<pii> &a){
	int res=0, n=a.size();
	rep(i, 0, n-1) rep(j, i+1, n-1) res=max(res, max(abs(a[i].x-a[j].x), abs(a[i].y-a[j].y)));
	return res;
}

// bool inb[N];
set<int> b;

bool ok(int g){
	vector<int> a;
	// rep(i, 1, n) inb[i]=true;
	b.clear();
	rep(i, 2, n) b.insert(i);
	a.pb(1);
	rep(i, 2, n){
		if(w[i].x>w[1].x+g) break;
		else a.pb(i);
	}
	sort(all(a), [&](int fir, int sec){
		return w[fir].y<w[sec].y;
	});
	// for(auto e: b) debug(e);
	
	vector<pii> buf;
	
	int m=a.size();
	// inb[a[0]]=false;
	b.erase(a[0]);
	for(int l=0, r=0; l<m; l++){
		while(r+1<m && w[a[r+1]].y-w[a[l]].y<=g){
			r++;
			// inb[a[r]]=false;
			b.erase(a[r]);
		}
		
		buf.clear();
		for(auto e: b) buf.pb(w[e]);
		// for(auto e: b) cerr<<e<<" ";
		// cerr<<endl;
		if(cal(buf)<=g) return true;
		
		// inb[a[l]]=true;
		b.insert(a[l]);
	}
	return false;
}

signed main(){
	cin>>n;
	rep(i, 1, n){
		int x, y; read(x), read(y);
		w[i]={x+y, x-y};
	}
	sort(w+1, w+1+n);
	// rep(i, 1, n) cerr<<w[i].x<<" "<<w[i].y<<"\n";
	// debug(ok(7));
	// debug("=======");
	
	int l=0, r=2020;
	while(l<r){
		int mid=l+r>>1;
		if(ok(mid)) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

input:

2
0 0
5 5

output:

0

result:

ok single line: '0'

Test #2:

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

input:

6
1 1
4 1
1 5
10 10
10 8
7 10

output:

7

result:

ok single line: '7'

Test #3:

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

input:

3
0 10
100 11
100 9

output:

2

result:

ok single line: '2'

Test #4:

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

input:

7
0 0
100 100
0 100
100 0
50 50
0 50
100 50

output:

100

result:

ok single line: '100'

Test #5:

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

input:

11
30 30
40 35
20 35
35 40
25 40
30 45
40 25
20 25
35 20
25 20
30 15

output:

20

result:

ok single line: '20'

Test #6:

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

input:

11
30 30
40 35
20 35
35 37
25 37
30 39
40 25
20 25
35 23
25 23
30 21

output:

20

result:

ok single line: '20'

Test #7:

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

input:

4
0 2
5 2
5 0
0 0

output:

2

result:

ok single line: '2'

Test #8:

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

input:

5
1 1
2 2
4 4
7 7
11 11

output:

8

result:

ok single line: '8'

Test #9:

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

input:

4
50 100
52 100
0 0
100 1

output:

101

result:

ok single line: '101'

Test #10:

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

input:

10
939 271
952 1000
0 239
281 919
891 0
1000 831
35 0
558 629
479 0
575 501

output:

1165

result:

ok single line: '1165'

Test #11:

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

input:

100
160 0
1000 650
484 541
1000 1000
714 312
1000 198
140 78
951 759
550 467
325 620
207 563
1000 667
16 0
205 298
370 133
1000 233
19 0
645 683
478 435
1000 588
328 0
831 281
306 904
857 995
110 302
746 718
637 0
780 1000
439 0
199 793
0 495
993 808
0 657
859 443
337 0
1000 749
348 343
274 739
0 41...

output:

1363

result:

ok single line: '1363'

Test #12:

score: 0
Accepted
time: 1296ms
memory: 3648kb

input:

1000
17 544
750 843
375 0
910 651
350 531
567 735
355 461
754 1000
959 128
641 1000
561 0
526 1000
204 652
221 437
38 757
1000 555
0 411
971 1000
315 813
893 1000
594 546
1000 821
399 452
942 614
582 0
601 747
375 180
613 308
1 162
946 639
876 538
370 747
377 318
624 519
26 158
505 1000
645 0
736 28...

output:

1491

result:

ok single line: '1491'

Test #13:

score: 0
Accepted
time: 165ms
memory: 3632kb

input:

500
381 593
999 1000
255 137
989 441
268 538
693 1000
113 0
1000 445
122 438
1000 997
0 177
757 1000
269 322
983 208
254 425
994 1000
539 46
828 1000
364 169
221 610
484 0
1000 904
294 496
138 633
0 504
901 185
0 640
569 1000
373 476
938 28
21 115
139 1000
0 62
452 890
418 332
759 483
36 0
828 699
3...

output:

1490

result:

ok single line: '1490'