QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#785875 | #1088. Border Similarity Undertaking | xzf_200906 | WA | 3ms | 15972kb | C++14 | 2.0kb | 2024-11-26 19:30:11 | 2024-11-26 19:30:13 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
using namespace std;
char mp[2005][2005];
struct MatGeter{
int x,y,n,m,flg;
void init(int x1,int y1,int x2,int y2,int flg_){
x=x1,y=y1,flg=flg_;
n=x2-x1+1,m=y2-y1+1;
}
char operator()(int i,int j){
if(flg) swap(i,j);
if(i>=n||j>=m||i<0||j<0) return 0;
return mp[i+x][j+y];
}
}mt;
int u[2005][2005],d[2005][2005],l[2005][2005],r[2005][2005];
int cntl[2005][2005],cntr[2005][2005];
LL ans=0;
void solve(int x1,int y1,int x2,int y2){
int n=x2-x1+1,m=y2-y1+1;
if(n<=1||m<=1) return;
mt.init(x1,y1,x2,y2,n>m);
if(n>m) swap(n,m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(mt(i,j)==mt(i-1,j)) u[i][j]=u[i-1][j]+1;
else u[i][j]=1;
if(mt(i,j)==mt(i,j-1)) l[i][j]=l[i][j-1]+1;
else l[i][j]=1;
}
for(int i=n-1;i>=0;i--)
for(int j=m-1;j>=0;j--){
if(mt(i,j)==mt(i+1,j)) d[i][j]=d[i+1][j]+1;
else d[i][j]=1;
if(mt(i,j)==mt(i,j+1)) r[i][j]=r[i][j+1]+1;
else r[i][j]=1;
}
int mid=((m-1)>>1);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
cntl[i][j]=cntr[i][j]=0;
}
for(int i=0;i<n;i++){
for(int j=mid-l[i][mid]+1;j<=mid;j++){
cntl[i][i-u[i][j]+1]++;
cntl[i][i+d[i][j]]--;
}
for(int j=mid+1;j<=mid+r[i][mid+1];j++){
cntr[i][i-u[i][j]+1]++;
cntr[i][i+d[i][j]]--;
}
for(int j=0;j<n;j++){
cntl[i][j]+=cntl[i][j-1];
cntr[i][j]+=cntr[i][j-1];
}
}
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++){
int val1,val2;
if(l[i][mid]<l[j][mid]) val1=cntl[i][j];
else val1=cntl[j][i];
if(r[i][mid+1]<r[j][mid+1]) val2=cntr[i][j];
else val2=cntr[j][i];
ans+=1ll*val1*val2;
}
if(mt.flg){
int mid=(x1+x2)>>1;
solve(x1,y1,mid,y2);
solve(mid+1,y1,x2,y2);
}
else{
int mid=(y1+y2)>>1;
solve(x1,y1,x2,mid);
solve(x1,mid+1,x2,y2);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>mp[i][j];
solve(0,0,n-1,m-1);
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15856kb
input:
3 5 zzzzz zxzxz zzzzz
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 3ms
memory: 15860kb
input:
4 4 abbc bcca babc acbb
output:
0
result:
ok answer is '0'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 15972kb
input:
12 12 abbabaaaaabb ababaaaaaabb aaabbbbbabbb aabababaaaba abbbaaabaaba baaababbbaba aaaaababbaaa bbabbbbbabaa bbbabbaabaaa aabbbaaaabba babaabababaa bababaabaaba
output:
44
result:
wrong answer expected '25', found '44'