ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213426 | #2068. 最长公共前缀 | ckliang | 11 | 379ms | 60076kb | C++ | 1.4kb | 2024-11-11 21:59:08 | 2024-11-11 23:09:56 |
answer
#include<bits/stdc++.h>
using namespace std;
const long long N=2010,k=131;
unsigned long long dig[N];
unsigned long long has[N][N][3];//0 i 1j 2ij
char s[N][N],opt1,opt2;
int n,m,q;
int ret(char s)
{
if( s=='V' )return 0;
if( s=='H' )return 1;
return 2;
}
int x1,y_1,x2,y2,t1,t2;
unsigned long long haaa(int x,int y,int t,int l)
{
if( t==0 )return has[x+l-1][y][t]-has[x-1][y][t]*dig[l];
if( t==1 )return has[x][y+l-1][t]-has[x][y-1][t]*dig[l];
if( t==2 )return has[x+l-1][y+l-1][t]-has[x-1][y-1][t]*dig[l];
}
bool ch(int x,int y,int t,int l)
{
if( t==0 )return x+l-1<=n;
if( t==1 )return y+l-1<=m;
return ch(x,y,0,l)&&ch(x,y,1,l);
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
dig[0]=1;
for( int i=1 ; i<N ; i++ )dig[i]=dig[i-1]*k;
for( int i=1 ; i<=n ; i++ )
{
for( int j=1 ; j<=m ; j++ )
{
cin>>s[i][j];
}
}
for( int i=1 ; i<=n ; i++ )
{
for( int j=1 ; j<=m ; j++ )
{
has[i][j][0]=has[i-1][j][0]*k+s[i][j]-'a';
has[i][j][1]=has[i][j-1][1]*k+s[i][j]-'a';
has[i][j][2]=has[i-1][j-1][2]*k+s[i][j]-'a';
}
}
while(q--)
{
cin>>x1>>y_1>>opt1>>x2>>y2>>opt2;
t1=ret(opt1);
t2=ret(opt2);
int l=0,r=max(n,m),mid;
while( l<r )
{
mid=(l+r+1)>>1;
if( ch(x1,y_1,t1,mid)==0 || ch(x2,y2,t2,mid)==0 )r=mid-1;
else
{
// cout<<l<<" "<<r<<endl;
if( haaa(x1,y_1,t1,mid)==haaa(x2,y2,t2,mid) )l=mid;
else r=mid-1;
}
}
cout<<l<<endl;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 154ms
memory: 50336kb
input:
1000 2000 10000 awanannwnnaaawwnwawanwnwaaaanwnaaananwawwwwnannannawwwawwaaaaannwnwnwnnaaawaawawannn...
output:
0 0 0 0 0 0 0 2 0 1 0 0 1 0 1 0 2 0 1 2 0 0 2 0 1 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 2 0 1 3 1 0 3 0 ...
result:
ok 10000 tokens
Test #2:
score: 0
Accepted
time: 225ms
memory: 60076kb
input:
2000 1000 10000 zzqzqqqqqzqqqqzqqqqzqzqzzzqqzqqqzzqzzqqqqqqqqqqqzzqzqqqzzqqzzqzqzzzqqzqqzzzzzzqzzzqq...
output:
0 3 3 1 0 2 2 2 1 0 1 0 0 0 1 0 2 0 6 1 0 1 1 0 2 1 1 1 2 4 0 1 3 2 1 0 1 2 0 0 0 1 1 0 1 1 0 4 0 3 ...
result:
ok 10000 tokens
Subtask #2:
score: 0
Time Limit Exceeded
Test #3:
score: 0
Time Limit Exceeded
input:
2000 2000 1000000 gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...
output:
1146 541 203 322 618 166 345 138 520 206 1031 667 741 921 361 1110 1057 372 899 209 491 69 93 639 14...
result:
Subtask #3:
score: 0
Skipped
Subtask #4:
score: 0
Skipped