QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#45437 | #1819. Cleaning Robot | vexentox | WA | 606ms | 315788kb | C++14 | 1.6kb | 2022-08-23 21:07:56 | 2022-08-23 21:07:59 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#define _for(i,L,R) for(int i=L;i<=R;++i)
#define build(n,m,k) vector<vector<int>>(n+1,vector<int>(m+1,k))
//#define int long long
using namespace std;
int n,m,k;
vector<vector<int>> g,sumg,h,sumh;
void calc(int &x,int &y)
{
x=max(1,x);y=max(1,y);
x=min(x,n);y=min(y,m);
}
int getg(int x1,int y1,int x2,int y2)
{
calc(x1,y1);calc(x2,y2);
return sumg[x2][y2]-sumg[x1-1][y2]-sumg[x2][y1-1]+sumg[x1-1][y1-1];
}
int geth(int x1,int y1,int x2,int y2)
{
calc(x1,y1);calc(x2,y2);
return sumh[x2][y2]-sumh[x1-1][y2]-sumh[x2][y1-1]+sumh[x1-1][y1-1];
}
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void dfs(int x,int y)
{
h[x][y]=0;
_for(i,0,3){
int nx=x+dx[i],ny=y+dy[i];
if(nx<1 or nx>n or ny<1 or ny>m or !h[nx][ny]) continue;
dfs(nx,ny);
}
}
bool check(int mid)
{
_for(i,1,n) _for(j,1,m){
h[i][j]=getg(i-mid+1,j-mid+1,i,j)==mid*mid;
sumh[i][j]=h[i][j]+sumh[i-1][j]+sumh[i][j-1]-sumh[i-1][j-1];
}
_for(i,1,n) _for(j,1,m) if(g[i][j] and !geth(i,j,i+mid-1,j+mid-1)) return 0;
_for(i,1,n) _for(j,1,m) if(h[i][j]){
dfs(i,j);
break;
}
_for(i,1,n) _for(j,1,m) if(h[i][j]) return 0;
return 1;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
g=build(n,m,1);
_for(i,0,n) g[i][0]=0;
_for(i,0,m) g[0][i]=0;
sumg=h=sumh=build(n,m,0);
while(k--){
int x,y;
scanf("%d%d",&x,&y);
g[x][y]=0;
}
_for(i,1,n) _for(j,1,m) sumg[i][j]=g[i][j]+sumg[i-1][j]+sumg[i][j-1]-sumg[i-1][j-1];
int l=0,r=min(n,m)+1;
while(l+1<r){
int mid=l+r>>1;
if(check(mid)) l=mid;
else r=mid;
}
if(!l) l=-1;
printf("%d\n",l);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3764kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 367ms
memory: 301640kb
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: 473ms
memory: 297324kb
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: 286ms
memory: 102964kb
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: 521ms
memory: 131612kb
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: 360ms
memory: 193384kb
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: 412ms
memory: 184012kb
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: 345ms
memory: 260420kb
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: 492ms
memory: 275760kb
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: 567ms
memory: 127624kb
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: 606ms
memory: 156352kb
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: 511ms
memory: 90980kb
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: 438ms
memory: 140452kb
input:
2236 2236 0
output:
2236
result:
ok answer is '2236'
Test #14:
score: 0
Accepted
time: 521ms
memory: 118412kb
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: 336ms
memory: 315788kb
input:
2236 2236 3 101 100 100 101 99 100
output:
1
result:
ok answer is '1'
Test #16:
score: -100
Wrong Answer
time: 344ms
memory: 315620kb
input:
2236 2236 4 101 100 100 101 99 100 100 99
output:
1
result:
wrong answer expected '-1', found '1'