QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672708 | #4681. Keyboarding | LJY_ljy | WA | 0ms | 57700kb | C++11 | 2.0kb | 2024-10-24 18:19:21 | 2024-10-24 18:19:22 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define se second
#define fi first
using namespace std;
const ll N=51;
ll n,m,dis[N][N][N][N],gx[9]={0,0,-1,1},gy[9]={1,-1,0,0},vis[N][N][N];
char a[N][N];queue<pair<ll,pair<ll,ll>>>que;
struct node{ll x,y,step,pos;};
inline void BFS(ll x,ll y)
{
dis[x][y][x][y]=0;
que.push(mp(x,mp(y,0)));
while(!que.empty())
{
pair<ll,pair<ll,ll>> now=que.front();
que.pop();//cout<<x<<' '<<y<<' '<<now.fi<<' '<<now.se.fi<<' '<<now.se.se<<endl;
for(int i=0;i<4;i++)
{
ll xx=now.fi,yy=now.se.fi,nx=xx+gx[i],ny=yy+gy[i];
while(nx>0 && nx<=n && ny>0 && ny<=m && a[nx][ny]==a[xx][yy])
xx=nx,yy=ny,nx=xx+gx[i],ny=yy+gy[i];
if(nx<1 || nx>n || ny<1 || ny>m) continue;
if(dis[x][y][nx][ny]>now.se.se+1)
{
dis[x][y][nx][ny]=now.se.se+1;
que.push(mp(nx,mp(ny,dis[x][y][nx][ny])));
}
}
}
}
int main()
{
ll sum=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j],
sum+=a[i][j]=='*';
memset(dis,0x3f,sizeof(dis));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
BFS(i,j);
string to;
cin>>to;to+="*";
queue<node>que;
que.push(node{1,1,0,0});
//cout<<"dis over\n";
// cout<<dis[1][18][1][1]<<endl;
// cout<<endl;
ll minn=INT_MAX,time_use=0;
memset(vis,0,sizeof(vis));
while(!que.empty())
{
node now=que.front();que.pop();
if(vis[now.x][now.y][now.pos]) continue;
vis[now.x][now.y][now.pos]=now.step;
// cout<<now.x<<' '<<now.y<<' '<<now.step<<' '<<now.pos<<endl;
if(now.pos==to.size())
{
minn=min(minn,now.step);
time_use++;
continue;
// return 0;
}
if(a[now.x][now.y]==to[now.pos])
que.push(node{now.x,now.y,now.step+1,now.pos+1});
else
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i][j]==to[now.pos] && dis[now.x][now.y][i][j]<=INT_MAX && (vis[i][j][now.pos+1]>now.step+dis[now.x][now.y][i][j]+1 || vis[i][j][now.pos+1]==0))
que.push(node{i,j,now.step+dis[now.x][now.y][i][j]+1,now.pos+1});
}
cout<<minn;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 57408kb
input:
4 7 ABCDEFG HIJKLMN OPQRSTU VWXYZ** CONTEST
output:
30
result:
ok 1 number(s): "30"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 57700kb
input:
5 20 12233445566778899000 QQWWEERRTTYYUUIIOOPP -AASSDDFFGGHHJJKKLL* --ZZXXCCVVBBNNMM--** -------------------- ACM-ICPC-WORLD-FINALS-2015
output:
184
result:
wrong answer 1st numbers differ - expected: '160', found: '184'