Codeforces Round #335 (Div. 2) B.Testing Robots

B. Testing Robots
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (x0, y0) of a rectangular squared field of size x × y, after that a mine will be installed into one of the squares of the field. It is supposed to conduct exactly x·y tests, each time a mine is installed into a square that has never been used before. The starting cell of the robot always remains the same.

After placing the objects on the field the robot will have to run a sequence of commands given by string s, consisting only of characters 'L', 'R', 'U', 'D'. These commands tell the robot to move one square to the left, to the right, up or down, or stay idle if moving in the given direction is impossible. As soon as the robot fulfills all the sequence of commands, it will blow up due to a bug in the code. But if at some moment of time the robot is at the same square with the mine, it will also blow up, but not due to a bug in the code.

Moving to the left decreases coordinate y, and moving to the right increases it. Similarly, moving up decreases the x coordinate, and moving down increases it.

The tests can go on for very long, so your task is to predict their results. For each k from 0 to length(s) your task is to find in how many tests the robot will run exactly k commands before it blows up.

Input

The first line of the input contains four integers x, y, x0, y0 (1 ≤ x, y ≤ 500, 1 ≤ x0 ≤ x, 1 ≤ y0 ≤ y) — the sizes of the field and the starting coordinates of the robot. The coordinate axis X is directed downwards and axis Y is directed to the right.

The second line contains a sequence of commands s, which should be fulfilled by the robot. It has length from 1 to 100 000 characters and only consists of characters 'L', 'R', 'U', 'D'.

Output

Print the sequence consisting of (length(s) + 1) numbers. On the k-th position, starting with zero, print the number of tests where the robot will run exactly k commands before it blows up.

Sample test(s)
Input
3 4 2 2
UURDRDRL
Output
1 1 0 1 1 1 1 0 6
Input
2 2 2 2
ULD
Output
1 1 1 1

Note

In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: .


题意:机器人碰到矿石会爆炸,走完命令s也会爆炸,在n*m的方格里放矿石,每个格子只放一次,每次机器人的起点的命令s都一样。输出机器人刚好走完k步后就爆炸的情况数(0<=k<=strlen(s))。
思路:只有矿石刚好放在机器人第k步的位置或者当k=命令行长度+1时,机器人就会爆炸(当k=strlen(s)+1时,机器人走完命令自动爆炸,与矿石位置无关)
#include <stdio.h>
#include <string.h>
#define maxn 100005
char op[maxn];
int ans [maxn], Map[505][505];
int main()
{
    int n, m, ex, ey, i;
    scanf("%d %d %d %d", &n, &m, &ex, &ey);
    scanf("%s", op);
    int len = strlen(op);
    ans[len] = n * m;
    for(i = 0;i < len;i++)
    {
        //printf("%d %d %c\n", ex, ey, op[i]);
        if(Map[ex][ey] == 0)
        {
            ans[len]--;
            ans[i] = 1;
            Map[ex][ey] = 1;
        }else ans[i] = 0;
        if(op[i] == 'U'){
            if(ex > 1)
                ex--;
        }
        else if(op[i] == 'D'){
            if(ex < n)
                ex++;
        }
        else if(op[i] == 'L'){
            if(ey > 1)
                ey--;
        }
        else if(op[i] == 'R'){
            if(ey < m)
                ey++;
               // printf("---\n");
        }
    }
    for(i = 0;i <= len;i++)
        printf("%d%c", ans[i], i<len?' ':'\n');
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值