QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#90067 | #1283. Paper-cutting | ExplodingKonjac | WA | 299ms | 3416kb | C++17 | 8.0kb | 2023-03-22 09:31:12 | 2023-03-22 09:31:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<22;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
};
class FastOutput: public FastIOBase
{
#ifdef OPENIOBUF
public:
inline void flush()
{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
protected:
inline void __putc(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
putc(x,target);
#endif
}
template<typename T>
inline void __write(T x)
{
static char stk[64],*top;top=stk;
if(x<0) return __putc('-'),__write(-x);
do *(top++)=x%10,x/=10; while(x);
for(;top!=stk;__putc(*(--top)+'0'));
}
public:
FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
inline void setTarget(FILE *f) { this->flush(),target=f; }
~FastOutput(){ flush(); }
#else
inline void setTarget(FILE *f) { target=f; }
#endif
template<typename ...T>
inline void writesp(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
template<typename ...T>
inline void writeln(const T &...x)
{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
inline FastOutput &operator <<(char x)
{ return __putc(x),*this; }
inline FastOutput &operator <<(const char *s)
{ for(;*s;__putc(*(s++)));return *this; }
inline FastOutput &operator <<(const string &s)
{ return (*this)<<s.c_str(); }
template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
inline FastOutput &operator <<(const T &x)
{ return __write(x),*this; }
}qout;
class FastInput: public FastIOBase
{
#ifdef OPENIOBUF
public:
inline void flush()
{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
protected:
inline char __getc()
{
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
return buf[buf_p++];
#else
return getc(target);
#endif
}
public:
#ifdef OPENIOBUF
FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
inline void setTarget(FILE *f) { this->flush(),target=f; }
#else
FastInput(FILE *f=stdin): FastIOBase(f){}
inline void setTarget(FILE *f) { target=f; }
#endif
inline char getchar() { return __getc(); }
template<typename ...T>
inline void read(T &...x)
{ initializer_list<int>{(this->operator>>(x),0)...}; }
inline FastInput &operator >>(char &x)
{ while(isspace(x=__getc()));return *this; }
template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
inline FastInput &operator >>(T &x)
{
static char ch,sym;x=sym=0;
while(isspace(ch=__getc()));
if(ch=='-') sym=1,ch=__getc();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
return sym?x=-x:x,*this;
}
inline FastInput &operator >>(char *s)
{
while(isspace(*s=__getc()));
for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
return *s='\0',*this;
}
inline FastInput &operator >>(string &s)
{
char str_buf[(1<<8)+1],*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=__getc()));
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
*p='\0',s.append(str_buf);
if(p!=buf_end) break;
}
return *this;
}
}qin;
} // namespace FastIO
using namespace FastIO;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
constexpr int INF=1e9;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif
int T,n,m;
vector<string> a;
vector<int> manacher(const string &str)
{
static char s[2000005];
static int p[2000005];
int len=0;
for(auto &c: str) s[++len]='#',s[++len]=c;
s[++len]='#',s[0]='$',s[len+1]='\0';
int pos=0,mx=0;
for(int i=1;i<=len;i++)
{
if(i<=mx) p[i]=min(mx-i+1,p[pos*2-i]);
while(s[i-p[i]]==s[i+p[i]]) p[i]++;
if(i+p[i]>mx) mx=i+p[i]-1,pos=i;
}
vector<int> res(len-2);
for(int i=2;i<len;i++) res[i-2]=(p[i]>>1);
return res;
}
vector<vector<int>> Rr,Cr;
void getR()
{
Rr=Cr=vector(n,vector(m,0));
for(int i=0;i<n;i++)
{
string tmp(a[i]);
auto res=manacher(tmp);
for(int j=0;j+1<m;j++) Rr[i][j]=res[j<<1|1];
}
for(int j=0;j<m;j++)
{
string tmp(n,0);
for(int i=0;i<n;i++) tmp[i]=a[i][j];
auto res=manacher(tmp);
for(int i=0;i+1<n;i++) Cr[i][j]=res[i<<1|1];
}
}
bool fl[1000005],fr[1000005],fu[1000005],fd[1000005];
void check()
{
static int tmp[1000005];
fill(fl,fl+n,false),fill(fr,fr+n,false);
fill(fu,fu+m,false),fill(fd,fd+m,false);
fl[0]=true,tmp[0]=1;
for(int i=1;i<n;i++)
{
int R=INF;
for(int j=0;j<m;j++) R=min(R,Cr[i-1][j]);
tmp[i]=tmp[i-1];
if(tmp[i-1]-tmp[i-R]+fl[i-R]) fl[i]=true;
tmp[i]+=fl[i];
}
fr[n-1]=true,tmp[n-1]=1;
for(int i=n-2;~i;i--)
{
int R=INF;
for(int j=0;j<m;j++) R=min(R,Cr[i][j]);
tmp[i]=tmp[i+1];
if(tmp[i+1]-tmp[i+R]+fr[i+R]) fr[i]=true;
tmp[i]+=fr[i];
}
fu[0]=true,tmp[0]=1;
for(int j=1;j<m;j++)
{
int R=INF;
for(int i=0;i<n;i++) R=min(R,Rr[i][j-1]);
tmp[j]=tmp[j-1];
if(tmp[j-1]-tmp[j-R]+fu[j-R]) fu[j]=true;
tmp[j]+=fu[j];
}
fd[m-1]=true,tmp[m-1]=1;
for(int j=m-2;~j;j--)
{
int R=INF;
for(int i=0;i<n;i++) R=min(R,Rr[i][j]);
tmp[j]=tmp[j+1];
if(tmp[j+1]-tmp[j+R]+fd[j+R]) fd[j]=true;
tmp[j]+=fd[j];
}
}
constexpr int dirs[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
vector<int> lnxt,unxt;
int fa[1000005],mnx[1000005],mxx[1000005],mny[1000005],mxy[1000005];
inline int findFa(int x) { return x!=fa[x]?fa[x]=findFa(fa[x]):x; }
inline void merge(int x,int y)
{
x=findFa(x),y=findFa(y);
if(x==y) return;
mnx[x]=min(mnx[x],mnx[y]),mxx[x]=max(mxx[x],mxx[y]);
mny[x]=min(mny[x],mny[y]),mxy[x]=max(mxy[x],mxy[y]);
fa[y]=x;
}
void prework()
{
lnxt=vector(n,0),lnxt[n-1]=n-1;
for(int i=n-2;~i;i--) lnxt[i]=(fr[i]?i:lnxt[i+1]);
unxt=vector(m,0),unxt[m-1]=m-1;
for(int i=m-2;~i;i--) unxt[i]=(fd[i]?i:unxt[i+1]);
iota(fa,fa+n*m,0);
for(int i=0;i<n;i++) for(int j=0;j<m;j++)
{
int id=i*m+j;
mnx[id]=mxx[id]=i;
mny[id]=mxy[id]=j;
}
for(int i=0;i<n;i++) for(int j=0;j<m;j++)
{
if(a[i][j]!='0') continue;
for(auto &[dx,dy]: dirs)
{
int x=i+dx,y=j+dy;
if(x<0 || x>=n || y<0 || y>=m) continue;
if(a[x][y]!='0') continue;
merge(i*m+j,x*m+y);
}
}
}
struct Rect
{
int l,r,u,d,id;
Rect()=default;
Rect(int _l,int _r,int _u,int _d,int _i=0): l(_l),r(_r),u(_u),d(_d),id(_i){}
};
vector<Rect> q;
UI tot,sum[1000005];
void solve(int X,int Y,int sym)
{
vector s(n,vector(m,0u));
for(auto [l,r,u,d,id]: q) if(!id)
{
r-=X,d-=Y;
if(l>r || u>d) continue;
s[l][u]++;
if(r+1<n) s[r+1][u]--;
if(d+1<m) s[l][d+1]--;
if(r+1<n && d+1<m) s[r+1][d+1]++;
}
for(int i=0;i<n;i++) for(int j=0;j<m;j++)
{
if(i) s[i][j]+=s[i-1][j];
if(j) s[i][j]+=s[i][j-1];
if(i && j) s[i][j]-=s[i-1][j-1];
}
for(int i=0;i<n;i++) for(int j=0;j<m;j++)
{
if(i) s[i][j]+=s[i-1][j];
if(j) s[i][j]+=s[i][j-1];
if(i && j) s[i][j]-=s[i-1][j-1];
}
for(auto [l,r,u,d,id]: q) if(id)
{
r-=X,d-=Y;
if(l>r || u>d) continue;
sum[id]+=sym*s[r][d];
if(l) sum[id]-=sym*s[l-1][d];
if(u) sum[id]-=sym*s[r][u-1];
if(l && u) sum[id]+=sym*s[l-1][u-1];
}
}
int main()
{
qin>>T;
while(T--)
{
qin>>n>>m;
a=vector(n,string(m,0));
for(int i=0;i<n;i++) qin>>a[i];
getR();
check();
prework();
q.clear(),tot=0;
for(int i=0,id=0;i<n;i++) for(int j=0;j<m;j++,id++)
if(a[i][j]=='0' && findFa(id)==id)
q.emplace_back(mnx[id],mxx[id],mny[id],mxy[id]);
for(int i=0;i<n;i++) for(int j=0;j<m;j++)
if(fl[i] && fu[j] && lnxt[i]<n && unxt[j]<m)
sum[++tot]=0,q.emplace_back(i,lnxt[i],j,unxt[j],tot);
solve(0,0,1);
solve(0,1,-1);
solve(1,0,-1);
solve(1,1,1);
qout<<*max_element(sum+1,sum+tot+1)<<'\n';
}
return 0;
}
/*
3
2 5
11001
11001
5 7
1001100
0110011
0101101
0010010
1000000
3 2
11
11
11
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3400kb
input:
3 2 5 11001 11001 5 7 1001100 0110011 0101101 0010010 1000000 3 2 11 11 11
output:
1 4 0
result:
ok 3 tokens
Test #2:
score: -100
Wrong Answer
time: 299ms
memory: 3416kb
input:
100000 3 3 010 101 101 4 2 10 10 10 10 4 2 11 00 00 11 7 1 1 0 0 1 1 0 0 6 1 1 0 0 1 1 1 5 2 11 00 00 11 11 10 1 1 0 0 0 0 0 0 0 0 1 9 1 0 0 0 0 0 0 0 0 0 10 1 1 1 1 1 1 1 1 1 1 0 9 1 0 0 0 0 0 0 1 1 0 1 10 0010000100 7 1 0 0 0 0 0 0 0 4 2 00 00 00 00 7 1 0 1 0 0 0 0 1 10 1 1 0 0 0 0 0 0 0 0 1 9 1 1...
output:
3 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 2 1 1 1 0 1 0 2 1 1 1 1 1 1 0 1 2 3 1 2 1 2 2 1 0 1 1 1 2 1 1 1 1 1 1 3 0 1 1 1 1 1 1 1 1 0 3 2 1 3 1 1 3 1 1 1 2 1 1 1 1 1 3 2 1 1 0 1 1 1 2 2 1 1 1 1 2 2 1 2 2 3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 2 2 2 1 1 5 1 1 1 2 1 1 2 2 2 2 2 1 1 1 2 2 2 1 1 2 2 1 3 1 1 2 1 ...
result:
wrong answer 32nd words differ - expected: '2', found: '1'