QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19215 | #1819. Cleaning Robot | foreverlasting# | AC ✓ | 3752ms | 557052kb | C++20 | 6.0kb | 2022-01-28 14:49:50 | 2022-05-06 04:28:10 |
Judging History
answer
//2022.1.28 by ljz
//email [email protected]
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define res int
#define LL long long
#define Inf 0x3f3f3f3f
#define sup 0x7fffffff
#define inf 0x3f3f3f3f
#define INF 2000000000000000000
//#define unl __int128
#define eps 1e-10
#define RG
#define db double
#define pc(x) __builtin_popcount(x)
#define ctz(x) __builtin_ctz(x)
//#define pc(x) __builtin_popcountll(x)
typedef pair<int,int> Pair;
//#define poly vector<int>
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define uint unsigned int
#define lowbit(x) ((x)&-(x))
#define gc getchar
#define ld long db
//template <class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//inline int gc() {
// static char buf[100000],*p1,*p2;
// return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//char sr[1<<21],z[20];
//int C=-1,Z=0;
//inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
//inline void print(RG LL x){
// if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
// while(z[++Z]=x%10+48,x/=10);
// while(sr[++C]=z[Z],--Z);
//}
template <typename T> inline void Read(T &x) {
res c=gc();
bool f=false;
for(x=0;!isdigit(c);c=gc())if(c=='-')f=true;
for(;isdigit(c);c=gc())x=x*10+c-'0';
if(f)x=-x;
}
inline int read() {
res s=0,ch=gc(),w=1;
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
else if(ch==EOF)break;
ch=gc();
}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
return s*w;
}
inline LL Read() {
RG LL s=0;
res ch=gc(),w=1;
while(ch<'0'||ch>'9'){
if(ch=='-')w=-1;
else if(ch==EOF)break;
ch=gc();
}
while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
return s*w;
}
inline void write(RG __int128 x){
if(x>10)write(x/10);
putchar(int(x%10)+'0');
}
const int kcz=998244353;
const int G=3,GI=332748118;
//inline void add(res &x,const res &y){
// x+=y,x>=kcz?x-=kcz:1;
//}
//inline int Add(const res &x,const res &y){
// return x+y>=kcz?x+y-kcz:x+y;
//}
//inline int mul(const res &x,const res &y){
// return int(1ll*x*y%kcz);
//}
#define add(x,y) ((x)+=(y),(x)>=kcz?(x)-=kcz:1)
#define Add(x,y) ((x)+(y)>=kcz?(x)+(y)-kcz:(x)+(y))
#define mul(x,y) (int)((LL)(x)*(y)%kcz)
#define Mul(x,y,d) (int)((ull)(x)*(y)/(d)%kcz)
inline int qpow(res x,res y=kcz-2){
res ret=1;
while(y){
if(y&1)ret=mul(ret,x);
x=mul(x,x),y>>=1;
}
return ret;
}
inline int qpow(res x,res y,const res &ljc){
res ret=1;
while(y){
if(y&1)ret=(int)(1ll*ret*x%ljc);
x=(int)(1ll*x*x%ljc),y>>=1;
}
return ret;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//cloclim_t start=cloclim();
//inline void clim(){
// if(1.0*(cloclim()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
//2022.1.28 by ljz
//email [email protected]
//if you find any bug in my code
//please tell me
const int N=5e6+10;
const int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
namespace MAIN{
int n,m,k;
vector<int> A[N],B[N],C[N];
Pair Q[N];
int he,ta;
int vis[N];
inline int bfs(const res &si,const res &sj,const res &L){
for(res i=1;i<=n*m;i++)vis[i]=0;
Q[he=ta=1]=mp(si,sj),vis[(si-1)*m+sj]=1;
while(he<=ta){
auto [x,y]=Q[he++];
for(res l=0;l<4;l++){
res nx=x+dx[l],ny=y+dy[l];
if(nx<1||ny<1||nx>n||ny>m)continue;
if(C[nx][ny])continue;
if(vis[(nx-1)*m+ny])continue;
if(nx+L-1<=n&&ny+L-1<=m){
res t=A[nx+L-1][ny+L-1]-A[nx+L-1][ny-1]-A[nx-1][ny+L-1]+A[nx-1][ny-1];
if(t)continue;
B[nx][ny]++,B[nx+L][ny]--,B[nx][ny+L]--,B[nx+L][ny+L]++;
Q[++ta]=mp(nx,ny),vis[(nx-1)*m+ny]=1;
}
}
}
return ta;
}
inline void MAIN(){
n=read(),m=read(),k=read();
for(res i=0;i<=n+1;i++)A[i].resize(m+2),C[i].resize(m+2);
for(res i=1;i<=k;i++){
res x=read(),y=read();
A[x][y]=C[x][y]=1;
}
for(res i=1;i<=n;i++)for(res j=1;j<=m;j++){
A[i][j]+=A[i-1][j]+A[i][j-1]-A[i-1][j-1];
}
res l=1,r=min(n,m),ret=0;
while(l<=r){
res mid=(l+r)>>1;
for(res i=0;i<=n+1;i++)vector<int>(m+2).swap(B[i]);
for(res i=1;i<=n;i++){
res fl=0;
for(res j=1;j<=m;j++){
if(i+mid-1<=n&&j+mid-1<=m){
res t=A[i+mid-1][j+mid-1]-A[i+mid-1][j-1]-A[i-1][j+mid-1]+A[i-1][j-1];
// if(mid==3)printf("%d %d %d\n",i,j,t);
if(!t){
B[i][j]++,B[i+mid][j]--,B[i][j+mid]--,B[i+mid][j+mid]++;
bfs(i,j,mid),fl=1;break;
}
}
}
if(fl)break;
}
for(res i=1;i<=n;i++)for(res j=1;j<=m;j++)B[i][j]+=B[i-1][j]+B[i][j-1]-B[i-1][j-1];
res fl=0;
for(res i=1;i<=n;i++){
for(res j=1;j<=m;j++){
if(C[i][j])continue;
// if(mid==3)printf("%d %d %d\n",i,j,B[i][j]);
if(!B[i][j]){fl=1;break;}
}
if(fl)break;
}
if(fl)r=mid-1;
else l=mid+1,ret=mid;
}
printf("%d\n",!ret?-1:ret);
}
}
int main(){
// srand(time(0));
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
res Case=1;
for(res T=1;T<=Case;T++)MAIN::MAIN();
// Ot();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 95ms
memory: 355280kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 1801ms
memory: 472476kb
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: 2037ms
memory: 472556kb
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: 359ms
memory: 440432kb
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: 981ms
memory: 460016kb
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: 648ms
memory: 460540kb
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: 751ms
memory: 459484kb
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: 2137ms
memory: 472216kb
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: 2078ms
memory: 472184kb
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: 1127ms
memory: 456896kb
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: 960ms
memory: 464880kb
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: 323ms
memory: 435544kb
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: 451ms
memory: 443284kb
input:
2236 2236 0
output:
2236
result:
ok answer is '2236'
Test #14:
score: 0
Accepted
time: 412ms
memory: 439644kb
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: 3752ms
memory: 472624kb
input:
2236 2236 3 101 100 100 101 99 100
output:
1
result:
ok answer is '1'
Test #16:
score: 0
Accepted
time: 3731ms
memory: 472536kb
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: 96ms
memory: 355332kb
input:
50 50 2 25 25 28 26
output:
22
result:
ok answer is '22'
Test #18:
score: 0
Accepted
time: 92ms
memory: 355280kb
input:
6 3 3 4 1 4 2 4 3
output:
-1
result:
ok answer is '-1'
Test #19:
score: 0
Accepted
time: 87ms
memory: 355164kb
input:
3 3 2 1 1 3 3
output:
1
result:
ok answer is '1'
Test #20:
score: 0
Accepted
time: 79ms
memory: 355324kb
input:
3 133 1 1 1
output:
2
result:
ok answer is '2'
Test #21:
score: 0
Accepted
time: 87ms
memory: 356228kb
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: 500ms
memory: 557052kb
input:
1666666 3 1 1 1
output:
2
result:
ok answer is '2'
Test #23:
score: 0
Accepted
time: 64ms
memory: 355208kb
input:
6 6 2 1 3 3 4
output:
2
result:
ok answer is '2'
Test #24:
score: 0
Accepted
time: 192ms
memory: 504512kb
input:
3 1666666 1 1 1
output:
2
result:
ok answer is '2'