QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#33161#1819. Cleaning Robotbulijiojiodibuliduo#AC ✓1273ms458960kbC++2.2kb2022-05-29 02:29:472022-05-29 02:29:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-29 02:29:49]
  • 评测
  • 测评结果:AC
  • 用时:1273ms
  • 内存:458960kb
  • [2022-05-29 02:29:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
int n,m,k;
int main() {
	scanf("%d%d%d",&n,&m,&k);
	vector<vector<int>> ob(n+1,VI(m+1,0));
	vector<vector<int>> ob2(n,VI(m,0));
	rep(i,0,k) {
		int u,v;
		scanf("%d%d",&u,&v);
		ob[u][v]=1;
		ob2[u-1][v-1]=1;
	}
	rep(i,1,n+1) rep(j,1,m+1) ob[i][j]+=ob[i][j-1];
	rep(i,1,n+1) rep(j,1,m+1) ob[i][j]+=ob[i-1][j];
	PII fp(-1,-1);
	per(i,0,n) per(j,0,m) if (ob2[i][j]==0) fp=mp(i,j);
	int l=0,r=min(n,m)+1;
	auto check=[&](int x) {
		vector<vector<int>> pos(n,VI(m,0));
		vector<vector<int>> vis(n,VI(m,0));
		vector<vector<int>> mark(n+1,VI(m+1,0));
		rep(i,0,n) rep(j,0,m) if (i+x<=n&&j+x<=m) {
			int v=ob[i+x][j+x]-ob[i+x][j]-ob[i][j+x]+ob[i][j];
			if (v==0) {
				pos[i][j]=1;
			}
		}
		if (pos[fp.fi][fp.se]==0) return false;
		queue<PII> q;
		vis[fp.fi][fp.se]=1;
		q.push(fp);
		while (!q.empty()) {
			auto [x, y]=q.front();
			q.pop();
			rep(d,0,4) if (x+dx[d]>=0&&x+dx[d]<n&&y+dy[d]>=0&&y+dy[d]<m) {
				int nx=x+dx[d],ny=y+dy[d];
				if (pos[nx][ny]==1&&!vis[nx][ny]) {
					vis[nx][ny]=1;
					q.push({nx,ny});
				}
			}
		}
		rep(i,0,n) rep(j,0,m) if (vis[i][j]) {
			mark[i][j]++; mark[i+x][j+x]++; mark[i][j+x]--; mark[i+x][j]--;
		}
		rep(i,0,n) rep(j,1,m) mark[i][j]+=mark[i][j-1];
		rep(i,1,n) rep(j,0,m) mark[i][j]+=mark[i-1][j];
		rep(i,0,n) rep(j,0,m) if (ob2[i][j]==0&&mark[i][j]==0) return false;
		return true;
	};
	while (l+1<r) {
		int md=(l+r)>>1;
		if (check(md)) l=md; else r=md;
	}
	if (l==0) l=-1;
	printf("%d\n",l);
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3740kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 951ms
memory: 101820kb

input:

2236 2236 2214
28 1255
389 2175
730 592
1360 977
1225 752
1403 1798
1518 1381
147 745
659 249
951 1475
1826 1951
691 1033
81 1458
1487 1946
2106 1395
1995 629
470 891
1902 822
2210 2001
441 2130
1198 1539
2027 1101
215 1149
205 420
379 2104
308 1225
859 109
1417 2078
1764 376
1772 5
335 1113
917 118...

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1089ms
memory: 101396kb

input:

2236 2236 2143
228 686
129 801
1105 382
2196 1919
2082 777
1672 268
174 916
234 491
1235 274
1645 1849
1114 1173
1351 1677
1294 1365
1059 197
611 1715
1769 1395
885 1902
1190 1304
1039 779
610 124
881 662
22 1664
239 1283
2218 2031
169 1417
291 143
228 1837
1518 2013
747 359
1997 1030
73 153
614 488...

output:

3

result:

ok answer is '3'

Test #4:

score: 0
Accepted
time: 373ms
memory: 101400kb

input:

2236 2236 63774
369 1861
1156 2150
1895 160
546 1944
1688 645
49 1888
430 973
1602 30
1988 971
1120 1307
322 1524
1559 1070
558 1147
973 1965
572 923
370 646
1436 1982
132 681
1410 308
1812 982
2191 2112
1311 396
1067 1330
659 477
873 881
1766 508
2091 1875
895 716
2058 1237
1374 1005
2183 1514
227 ...

output:

8

result:

ok answer is '8'

Test #5:

score: 0
Accepted
time: 733ms
memory: 101480kb

input:

2236 2236 27245
1371 170
575 488
1594 575
1537 77
491 1580
1761 764
783 1265
242 923
893 71
1455 671
114 1289
1901 1481
1962 1160
861 2198
1055 89
2019 1481
1012 1415
1023 92
421 2018
1788 2006
1559 263
1387 1496
1556 479
166 1085
1368 2156
2076 2156
1028 617
919 146
698 1544
1730 2111
871 1478
768 ...

output:

16

result:

ok answer is '16'

Test #6:

score: 0
Accepted
time: 521ms
memory: 101452kb

input:

2000 2500 30907
892 176
1238 2180
1711 176
1953 1556
793 44
336 1844
850 536
71 104
730 1052
892 1112
332 608
483 2144
45 572
240 104
201 416
1251 2024
1428 2000
402 1412
1240 1940
1689 1412
399 680
1349 1964
1290 464
1117 944
158 584
608 92
1947 1964
1042 1676
1865 1196
196 2264
1520 1724
1411 1544...

output:

11

result:

ok answer is '11'

Test #7:

score: 0
Accepted
time: 604ms
memory: 101480kb

input:

2500 2000 33483
2270 1836
1874 828
866 108
1066 220
1616 780
396 140
85 1012
2107 1492
630 1148
710 1452
688 1804
834 1196
524 1404
400 1228
1031 132
1967 1428
1480 1804
996 44
134 588
1361 900
541 1492
186 1196
835 532
1339 676
628 1468
615 308
740 540
2139 1556
1299 1892
702 1868
670 652
1201 1444...

output:

12

result:

ok answer is '12'

Test #8:

score: 0
Accepted
time: 1154ms
memory: 101400kb

input:

2236 2236 2111
809 773
1351 157
1378 427
461 1897
584 2078
285 1146
283 717
421 933
1449 726
559 799
350 1344
1018 1081
106 1517
2212 870
842 1225
1717 599
338 104
92 2027
1198 915
220 568
2079 31
1611 1532
100 251
675 1098
745 1368
1879 669
941 1303
1370 1445
344 1203
473 494
539 723
1385 1813
1360...

output:

4

result:

ok answer is '4'

Test #9:

score: 0
Accepted
time: 1104ms
memory: 101412kb

input:

2236 2236 2241
490 710
1582 1095
868 1869
970 1216
224 445
1901 2198
1592 732
706 696
456 2051
1107 2064
717 1109
1205 1860
510 1472
832 1607
1005 1665
644 794
858 494
1353 408
1661 306
171 1381
1586 969
174 897
896 232
120 1538
1351 1526
654 2039
1884 896
1995 1130
1492 1309
279 1674
2028 1526
1271...

output:

5

result:

ok answer is '5'

Test #10:

score: 0
Accepted
time: 819ms
memory: 101404kb

input:

2236 2236 999999
577 1462
1623 1266
1158 1238
914 1218
53 674
1599 138
395 298
1308 30
387 130
1077 1154
448 654
485 166
817 2090
769 170
549 1070
432 1390
537 686
1298 1630
989 762
133 1342
184 786
1631 1226
612 610
987 1538
1107 1394
345 678
413 2174
768 250
208 1014
393 302
70 966
845 974
1001 11...

output:

3

result:

ok answer is '3'

Test #11:

score: 0
Accepted
time: 794ms
memory: 101900kb

input:

2235 2237 999999
1645 1632
354 1487
1812 2041
551 1450
119 1290
1498 63
205 1404
111 1158
347 1482
1179 1234
222 955
1241 2004
674 2167
361 1864
1469 332
962 571
76 1897
369 2048
36 225
1420 1845
84 265
1814 711
661 2124
429 1840
1669 1756
93 456
73 252
1539 954
824 1585
1010 895
135 1014
635 858
14...

output:

1

result:

ok answer is '1'

Test #12:

score: 0
Accepted
time: 516ms
memory: 101532kb

input:

2236 2236 999999
1992 1723
1730 2026
371 172
102 634
231 514
1676 1817
182 23
237 590
1505 2003
509 23
1825 2200
2198 2166
690 209
359 333
300 203
705 280
1490 2042
1890 1928
118 420
238 473
229 424
1629 1986
232 63
1534 2181
38 566
206 576
244 624
2161 1350
1790 2180
2108 1876
1983 1902
1813 1911
2...

output:

1236

result:

ok answer is '1236'

Test #13:

score: 0
Accepted
time: 373ms
memory: 101852kb

input:

2236 2236 0

output:

2236

result:

ok answer is '2236'

Test #14:

score: 0
Accepted
time: 469ms
memory: 101484kb

input:

2236 2236 999696
2168 692
2143 1995
2047 1638
2229 308
13 2235
379 2158
1020 2105
2011 1721
216 2137
404 2125
1609 2011
2228 645
28 2071
2187 942
1489 2167
1424 2207
1228 2160
2219 1653
1532 2126
2007 1350
2125 1219
2190 673
2142 54
1237 2043
2191 636
2095 765
2053 2059
2083 723
1587 2044
2083 1187
...

output:

2000

result:

ok answer is '2000'

Test #15:

score: 0
Accepted
time: 1245ms
memory: 101856kb

input:

2236 2236 3
101 100
100 101
99 100

output:

1

result:

ok answer is '1'

Test #16:

score: 0
Accepted
time: 1273ms
memory: 101836kb

input:

2236 2236 4
101 100
100 101
99 100
100 99

output:

-1

result:

ok answer is '-1'

Test #17:

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

input:

50 50 2
25 25
28 26

output:

22

result:

ok answer is '22'

Test #18:

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

input:

6 3 3
4 1
4 2
4 3

output:

-1

result:

ok answer is '-1'

Test #19:

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

input:

3 3 2
1 1
3 3

output:

1

result:

ok answer is '1'

Test #20:

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

input:

3 133 1
1 1

output:

2

result:

ok answer is '2'

Test #21:

score: 0
Accepted
time: 8ms
memory: 4504kb

input:

200 200 4
101 100
100 101
103 102
102 103

output:

1

result:

ok answer is '1'

Test #22:

score: 0
Accepted
time: 813ms
memory: 458960kb

input:

1666666 3 1
1 1

output:

2

result:

ok answer is '2'

Test #23:

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

input:

6 6 2
1 3
3 4

output:

2

result:

ok answer is '2'

Test #24:

score: 0
Accepted
time: 186ms
memory: 133440kb

input:

3 1666666 1
1 1

output:

2

result:

ok answer is '2'