QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83549 | #1283. Paper-cutting | eyiigjkn | WA | 6ms | 17856kb | C++14 | 2.7kb | 2023-03-02 14:53:27 | 2023-03-02 14:53:30 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Hash=pair<int,int>;
constexpr int p1=1e9+7,p2=1e9+9,Base=998244353;
char _s[3000010],*s[1000010];
bool vis[1000010];
Hash pw[1000010],_s1[3000010],*s1[1000010],_s2[3000010],*s2[1000010];
inline Hash operator+(const Hash &x,const Hash &y){return {(x.first+y.first)%p1,(x.second+y.second)%p2};}
inline Hash operator-(const Hash &x,const Hash &y){return {(x.first+p1-y.first)%p1,(x.second+p2-y.second)%p2};}
inline Hash operator*(const Hash &x,const Hash &y){return {(ll)x.first*y.first%p1,(ll)x.second*y.second%p2};}
int main()
{
int T,n,m;
cin>>T;
pw[0]={1,1};
for(int i=1;i<=1000000;i++) pw[i]=pw[i-1]*Hash{Base,Base};
while(T--)
{
int ans=0;
scanf("%d%d",&n,&m);
auto Id=[&](int x,int y){return (x-1)*m+y;};
for(int i=0,j=0;i<=n;i++,j+=m+1) s[i]=_s+j,s1[i]=_s1+j;
for(int i=1,j=0;i<=n+1;i++,j+=m+1) s2[i]=_s2+j;
for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
int x1=1,x2=n,y1=1,y2=m;
for(int j=1;j<=m;j++)
{
for(int i=1;i<=n;i++) s1[i][j]=s1[i-1][j]*Hash{Base,Base}+Hash{s[i][j],s[i][j]};
for(int i=n;i;i--) s2[i][j]=s2[i+1][j]*Hash{Base,Base}+Hash{s[i][j],s[i][j]};
}
auto chk1=[&](int x1,int x2)
{
if(x1>x2) return false;
int L=(x2-x1+1)/2;
for(int i=1;i<=m;i++)
if(s1[x1+L-1][i]-pw[L]*s1[x1-1][i]!=s2[x2-L+1][i]-pw[L]*s2[x2+1][i])
return false;
return true;
};
for(int i=2,j=n-1;i<=x2 || j>=x1;cout<<i<<" , "<<j<<endl,i+=2,j-=2)
if(chk1(x1,i)) x1=(x1+i+1)/2,i=x1-1,j=x2+1;
else if(chk1(j,x2)) x2=(x2+j-1)/2,i=x1-1,j=x2+1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++) s1[i][j]=s1[i][j-1]*Hash{Base,Base}+Hash{s[i][j],s[i][j]};
for(int j=m;j;j--) s2[i][j]=s2[i][j+1]*Hash{Base,Base}+Hash{s[i][j],s[i][j]};
}
auto chk2=[&](int y1,int y2)
{
if(y1>y2) return false;
int L=(y2-y1+1)/2;
for(int i=x1;i<=x2;i++)
if(s1[i][y1+L-1]-pw[L]*s1[i][y1-1]!=s2[i][y2-L+1]-pw[L]*s2[i][y2+1])
return false;
return true;
};
for(int i=2,j=m-1;i<=y2 || j>=y1;i+=2,j-=2)
if(chk2(y1,i)) y1=(y1+i+1)/2,i=y1-1,j=y2+1;
else if(chk2(j,y2)) y2=(y2+j-1)/2,i=y1-1,j=y2+1;
auto dfs=[&](auto dfs,int x,int y)->void
{
if(x<x1 || x>x2 || y<y1 || y>y2 || s[x][y]=='1' || vis[Id(x,y)]) return;
vis[Id(x,y)]=1;
dfs(dfs,x-1,y);dfs(dfs,x+1,y);
dfs(dfs,x,y-1);dfs(dfs,x,y+1);
};
for(int i=x1;i<=x2;i++)
for(int j=y1;j<=y2;j++)
if(s[i][j]=='0' && !vis[Id(i,j)])
ans++,dfs(dfs,i,j);
printf("%d\n",ans);
memset(vis+1,0,sizeof(bool)*n*m);
for(int i=1;i<=n;i++)
{
memset(s[i]+1,0,sizeof(char)*m);
memset(s1[i]+1,0,sizeof(Hash)*m);
memset(s2[i]+1,0,sizeof(Hash)*m);
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 17856kb
input:
3 2 5 11001 11001 5 7 1001100 0110011 0101101 0010010 1000000 3 2 11 11 11
output:
1 , 3 1 2 , 4 4 , 2 4 1 , 4 2 , 4 0
result:
wrong answer 2nd words differ - expected: '4', found: ','