#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<cctype>
#include<set>
#include<queue>
#define R0(i,n) for(int i=0;i<n;++i)
#define R1(i,n) for(int i=1;i<=n;++i)
#define CLR(x,c) memset(x,c,sizeof x)
using namespace std;
char str[505][505];
int dp[505][505];
int n,m,limit;
bool phone=0;
int main(){
scanf("%d%d%d",&n,&m,&limit);
R1(i,n)R1(j,m){
scanf(" %c", &str[i][j]);
str[i][j] = toupper(str[i][j]);
}
if(str[1][1]=='W'||str[n][m]=='W'||str[1][1]=='T'||str[n][m]=='T'){
printf("Oh my god!");
return 0;
}
else{
R1(i,n)R1(j,m){
if(i==1&&j==1)continue;
dp[i][j]=9999999;
if(str[i][j]=='W')continue;
if(str[i][j]=='A')phone=1;
if(i-1>=1&&dp[i-1][j]<dp[i][j])dp[i][j]=dp[i-1][j]+1;
if(j-1>=1&&dp[i][j-1]<dp[i][j])dp[i][j]=dp[i][j-1]+1;
if(str[i][j]=='T')dp[i][j]++;
}
}
if(phone && dp[n][m]<=limit)printf("%d", dp[n][m]);
else printf("Oh my god!");
return 0;
}
codevs1337 银行里的迷宫
最新推荐文章于 2023-08-28 13:45:37 发布