codeforces1327C. Game with Chips

C. Game with Chips

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya has a rectangular Board of size n×mn×m. Initially, kk chips are placed on the board, ii-th chip is located in the cell at the intersection of sxisxi-th row and syisyi-th column.

In one action, Petya can move all the chips to the left, right, down or up by 11 cell.

If the chip was in the (x,y)(x,y) cell, then after the operation:

  • left, its coordinates will be (x,y−1)(x,y−1);
  • right, its coordinates will be (x,y+1)(x,y+1);
  • down, its coordinates will be (x+1,y)(x+1,y);
  • up, its coordinates will be (x−1,y)(x−1,y).

If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.

Note that several chips can be located in the same cell.

For each chip, Petya chose the position which it should visit. Note that it's not necessary for a chip to end up in this position.

Since Petya does not have a lot of free time, he is ready to do no more than 2nm2nm actions.

You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in 2nm2nm actions.

Input

The first line contains three integers n,m,kn,m,k (1≤n,m,k≤2001≤n,m,k≤200) — the number of rows and columns of the board and the number of chips, respectively.

The next kk lines contains two integers each sxi,syisxi,syi (1≤sxi≤n,1≤syi≤m1≤sxi≤n,1≤syi≤m) — the starting position of the ii-th chip.

The next kk lines contains two integers each fxi,fyifxi,fyi (1≤fxi≤n,1≤fyi≤m1≤fxi≤n,1≤fyi≤m) — the position that the ii-chip should visit at least once.

Output

In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once.

In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters L,R,D,UL,R,D,Urespectively.

If the required sequence does not exist, print -1 in the single line.

Examples

input

Copy

3 3 2
1 2
2 1
3 3
3 2

output

Copy

3
DRD

input

Copy

5 4 3
3 4
3 1
3 3
5 3
1 3
1 4

output

Copy

9
DDLUUUURR

题意:

n * m大的方格里有 k 个点,给出每个点至少要访问一次的位置,每次可以将所有点向上、向下、向左、向右移动一个单位,问是否可以在 2 * n * m 步数内移动完成,如果可以输出一种移动方法。

(题目中没说要输出的移动方法必须 <= 2 * n * m

所以把整个网格扫描一遍就行了……

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;

int main()
{
    int n, m, k, x, y;
    while(~scanf("%d%d%d", &n, &m, &k))
    {
        for(int i = 1; i <= k; ++i)
        {
            scanf("%d%d", &x, &y);
        }
        for(int i = 1; i <= k; ++i)
        {
            scanf("%d%d", &x, &y);
        }
        string s = "";
        s += string(n - 1, 'U');
        s += string(m - 1, 'L');
        for(int i = 1; i <= n; ++i)
        {
            if(i & 1)
            {
                s += string(m - 1, 'R');
            }
            else
            {
                s += string(m - 1, 'L');
            }
            if(i < n)
                s += "D";
        }
        cout<<s.size()<<'\n';
        cout<<s<<'\n';
    }
    return 0;
}

 

全部评论

相关推荐

肖先生~:大一点得到公司面试更能学到点东西
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
6395次浏览 61人参与
# 你的实习产出是真实的还是包装的? #
1304次浏览 32人参与
# MiniMax求职进展汇总 #
23220次浏览 302人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7077次浏览 37人参与
# 简历第一个项目做什么 #
31329次浏览 315人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186521次浏览 1115人参与
# 巨人网络春招 #
11213次浏览 223人参与
# 研究所笔面经互助 #
118787次浏览 577人参与
# 面试紧张时你会有什么表现? #
30416次浏览 188人参与
# 简历中的项目经历要怎么写? #
309572次浏览 4163人参与
# 职能管理面试记录 #
10722次浏览 59人参与
# AI时代,哪些岗位最容易被淘汰 #
62719次浏览 748人参与
# 网易游戏笔试 #
6374次浏览 83人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6993次浏览 154人参与
# 腾讯音乐求职进展汇总 #
160437次浏览 1107人参与
# 从哪些方向判断这个offer值不值得去? #
56712次浏览 357人参与
# 正在春招的你,也参与了去年秋招吗? #
362741次浏览 2632人参与
# 你怎么看待AI面试 #
179417次浏览 1182人参与
# 小红书求职进展汇总 #
226905次浏览 1357人参与
# 你的房租占工资的比例是多少? #
92146次浏览 896人参与
# 校招笔试 #
467654次浏览 2954人参与
# 经纬恒润求职进展汇总 #
155713次浏览 1085人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务