QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19212 | #1819. Cleaning Robot | foreverlasting# | WA | 60ms | 355172kb | C++20 | 5.7kb | 2022-01-28 14:39:07 | 2022-05-06 04:27:56 |
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){
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;
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++){
if(!C[i][j]){
if(bfs(i,j)!=n*m-k){puts("-1");return;}
break;
}
}
}
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++){
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]++;
}
}
}
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);
}
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 60ms
memory: 355172kb
input:
10 7 1 8 3
output:
-1
result:
wrong answer expected '2', found '-1'