Result: Accepted
Time: 34ms
Memory: 1724kB
#include <bits/stdc++.h>
using namespace std;
char mp[100][100] ;
int n,m ;
int start_x, start_y, wt ;
int main(int argc, char const *argv[])
{
int t ;
scanf("%d",&t) ;
while(t --)
{
int flag = 0 ;
scanf("%d %d",&m,&n) ;
getchar() ;
for(int i = 0 ; i < m ; ++ i)
{
cin >> mp[i] ;
}
scanf("%d %d %c",&start_x,&start_y,&wt) ;
getchar() ;
string tmp ;
cin >> tmp ;
if(tmp == "U")
{
while(1)
{
start_x -- ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "D")
{
while(1)
{
start_x ++ ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "L")
{
while(1)
{
start_y -- ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "R")
{
while(1)
{
start_y ++ ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "LU")
{
while(1)
{
start_x -- ;
start_y -- ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "LD")
{
while(1)
{
start_x ++ ;
start_y -- ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "RU")
{
while(1)
{
start_x -- ;
start_y ++ ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
else if(tmp == "RD")
{
while(1)
{
start_x ++ ;
start_y ++ ;
if(start_x < 0 || start_x > m || start_y < 0 || start_y > n || mp[start_x][start_y] == '#')
{
flag = 1 ;
break ;
}
else if(mp[start_x][start_y] < wt)
{
break ;
}
}
}
if(flag) cout << "0" << endl ;
else cout << "1" << endl ;
}
return 0;
}