QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404918#7751. Palindrome PathSorting#AC ✓82ms28552kbC++205.8kb2024-05-05 00:30:542024-05-05 00:30:55

Judging History

你现在查看的是最新测评结果

  • [2024-05-05 00:30:55]
  • 评测
  • 测评结果:AC
  • 用时:82ms
  • 内存:28552kb
  • [2024-05-05 00:30:54]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using pii = pair<int, int>;
using ll = long long;
using vpii = vector<pii>;

using ppiii = pair<pii, int>;

using vb = vector<bool>;
using vvb = vector<vb>;

vi par;

pii operator+(pii a, pii b) {
    return {a.first + b.first, a.second + b.second};
}

pii operator-(pii a, pii b) {
    return {a.first - b.first, a.second - b.second};
}

pii moves[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
char ops[4] = {'U', 'D', 'R', 'L'};

void dfs(pii u, vvb &vis, vvb &grid, vi &seq) {
    int x, y;
    tie(x, y) = u;
    vis[x][y] = 1;
    for(int d = 0; d < 4; d++) {
        pii v = u + moves[d];
        if(vis[v.first][v.second]) continue;
        if(!grid[v.first][v.second]) continue;
        seq.push_back(d);
        dfs(v, vis, grid, seq);
        seq.push_back(d^1);
    }
}

pii follow(pii u, vi seq, vvb &grid, bool rev) {
    if(rev) {
        reverse(seq.begin(), seq.end());
    }
    for(int op : seq) {
        pii v;
        // if(!rev) {
             v = u + moves[op];
        // } else {
        //     v = u - moves[op];
        // }
        if(!grid[v.first][v.second]) continue;
        u = v;
    }
    return u;
}

const int N = 33;
bool vis[N][N][N][N];
int parop[N][N][N][N];
pair<pii, pii> parnode[N][N][N][N];

void find_path(vvb &grid, pii start2, pii end2) {
    memset(vis, 0, sizeof(vis));
    memset(parop, 0, sizeof(parop));
    memset(parnode, 0, sizeof(parnode));
    queue<pair<pii, pii>> q;
    q.push({start2, end2});
    parop[start2.first][start2.second][end2.first][end2.second] = -1;
    vis[start2.first][start2.second][end2.first][end2.second] = 1;
    while(!q.empty()) {
        pii s, e;
        tie(s, e) = q.front();
        q.pop();
        for(int d = 0; d < 4; d++) {
            pii s1 = s + moves[d];
            if(!grid[s1.first][s1.second]) {
                s1 = s;
            }
            for(int emove = 0; emove <= 1; emove++) {
                pii e1 = e;
                if(emove) {
                    e1 = e - moves[d];
                } else {
                    pii nxt = e + moves[d];
                    if(grid[nxt.first][nxt.second]) {
                        continue;
                    }
                }
                // cerr << s.first << ' ' << s.second << ' ' << e.first << ' ' << e.second << ' ' << s1.first << ' ' << s1.second << ' ' << e1.first << ' ' << e1.second << endl;
                if(!grid[e1.first][e1.second]) {
                    continue;
                }
                if(vis[s1.first][s1.second][e1.first][e1.second]) {
                    continue;
                }
                vis[s1.first][s1.second][e1.first][e1.second] = 1;
                parop[s1.first][s1.second][e1.first][e1.second] = d;
                parnode[s1.first][s1.second][e1.first][e1.second] = {s, e};
                q.push({s1, e1});
            }
        }
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    vvb grid(n+2, vb(m+2));
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < m; j++) {
            grid[i][j+1] = (s[j]-'0');
        }
    }
    
    pii start, end;
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        start = {x1, y1};
        end = {x2, y2};
    }

    vi tour_seq;
    vvb vis1(n+2, vb(m+2));
    dfs(start, vis1, grid, tour_seq);

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(grid[i][j] && !vis1[i][j]) {
                cout << "-1" << endl;
                return;
            }
        }
    }

    // for(int i : tour_seq) {
    //     cerr << ops[i];
    // }
    // cerr << endl;

    pii start1 = follow(start, tour_seq, grid, false);
    pii end1 = follow(end, tour_seq, grid, true);

    // start -> start
    // end -> end1
    find_path(grid, start, end);
    assert(vis[start.first][start.second][end1.first][end1.second]);
    vi path1;
    pair<pii, pii> cur = {start, end1};
    while(cur != make_pair(start, end)) {
        // cerr << cur.first.first << ' ' << cur.first.second << ' ' << cur.second.first << ' ' << cur.second.second << endl;
        path1.push_back(parop[cur.first.first][cur.first.second][cur.second.first][cur.second.second]);
        cur = parnode[cur.first.first][cur.first.second][cur.second.first][cur.second.second];
    }
    reverse(path1.begin(), path1.end());

    
    // cerr << end2.first << ' ' << end2.second << endl;


    // cerr << "loop done" << endl;

    find_path(grid, start1, end);

    pii goodp = {-1, -1};
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(vis[i][j][i][j]){
                goodp = {i, j};
            }
        }
    }
    assert(goodp.first != -1);
    // cerr << goodp.first << ' ' << goodp.second << endl;
    vi revseq;
    cur = {goodp, goodp};
    while(cur != make_pair(start1, end)) {
        // cerr << cur.first.first << ' ' << cur.first.second << ' ' << cur.second.first << ' ' << cur.second.second << endl;
        revseq.push_back(parop[cur.first.first][cur.first.second][cur.second.first][cur.second.second]);
        cur = parnode[cur.first.first][cur.first.second][cur.second.first][cur.second.second];
    }
    reverse(revseq.begin(), revseq.end());
    // cout << tour_seq << revseq << endl;
    string out = "";
    for(int i : path1) {
        out += ops[i];
    }
    // out += "|";
    for(int i : tour_seq) {
        out += ops[i];
    }
    // out += "|";
    for(int i : revseq) {
        out += ops[i];
    }
    // out += "|";
    cout << out;
    reverse(out.begin(), out.end());
    cout << out;
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 27908kb

input:

2 2
11
11
1 1 2 2

output:

DRUDLUDRRDULDURD

result:

ok Valid Solution (Length = 16).

Test #2:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

2 2
10
01
1 1 2 2

output:

-1

result:

ok No Solution.

Test #3:

score: 0
Accepted
time: 3ms
memory: 27864kb

input:

1 1
1
1 1 1 1

output:



result:

ok Valid Solution (Length = 0).

Test #4:

score: 0
Accepted
time: 3ms
memory: 27896kb

input:

5 4
1111
1111
1111
1111
1111
4 2 4 2

output:

DDDULLRUUURDDDDRUUUUDDDDLLLUUUUDDDDRRUUUULDDDUDDLLRRRRRRLLDDUDDDLUUUURRDDDDUUUULLLDDDDUUUURDDDDRUUURLLUDDD

result:

ok Valid Solution (Length = 106).

Test #5:

score: 0
Accepted
time: 0ms
memory: 28016kb

input:

5 5
11111
10101
11111
10101
11111
1 4 5 5

output:

RRRRLRDDDDLLUUUULLDDDDRLUURLUURRDDRLDDRRUUUULRDDDDDDDDRLUUUURRDDLRDDRRUULRUULRDDDDLLUUUULLDDDDRLRRRR

result:

ok Valid Solution (Length = 100).

Test #6:

score: 0
Accepted
time: 6ms
memory: 28092kb

input:

5 3
111
100
111
001
111
4 3 3 2

output:

URDULLUURRLLDDRRDDLLRRUDLUURRUULDURRLLDDRRDDLLRRUULLUDRU

result:

ok Valid Solution (Length = 56).

Test #7:

score: 0
Accepted
time: 0ms
memory: 27864kb

input:

5 4
1001
1101
1111
0011
0010
2 2 1 1

output:

ULRUDRDDURUUUDDDLULLUUDDRUUUDLLLRRUUDDDDUURRLLLDUUURDDUULLULDDDUUURUDDRDURLU

result:

ok Valid Solution (Length = 76).

Test #8:

score: 0
Accepted
time: 3ms
memory: 27880kb

input:

5 3
101
111
100
111
100
4 1 2 2

output:

ULDUUUDRRUDLLDDDURRLLRUUULDDLUUURLLRRUDDDLLDURRDUUUDLU

result:

ok Valid Solution (Length = 54).

Test #9:

score: 0
Accepted
time: 0ms
memory: 27900kb

input:

5 5
01110
10110
11110
11011
11100
2 4 5 1

output:

DDDUUULDDRDRLULLDDRLLUUUDDDRUURUULRRDDLLDDRRDDLLDDRRLUURUURDDDUUULLRDDLLULRDRDDLUUUDDD

result:

ok Valid Solution (Length = 86).

Test #10:

score: 0
Accepted
time: 0ms
memory: 27836kb

input:

5 3
011
111
110
111
011
3 1 2 1

output:

UUDLLURURDULDDDDRUDLULRUULDUUDDLLRRUDDURRLLDDUUDLUURLULDURDDDDLUDRURULLDUU

result:

ok Valid Solution (Length = 74).

Test #11:

score: 0
Accepted
time: 6ms
memory: 27820kb

input:

4 5
11111
11111
11111
11111
3 2 1 3

output:

UUUDDLLRUURDDDRUUURDDDUUULDDDLLLUUUDDDRRUUULDDUUUDDDLLRRRRRRRRLLDDDUUUDDLUUURRDDDUUULLLDDDLUUUDDDRUUURDDDRUURLLDDUUU

result:

ok Valid Solution (Length = 116).

Test #12:

score: 0
Accepted
time: 0ms
memory: 27880kb

input:

5 5
11111
10101
11111
10101
11111
2 5 1 1

output:

UUUUDULLDDDDRRUULRDDLLLLUUUURLDDRLDDRRUUUURRDUUUUDDDLLLLDDLLLLDDDUUUUDRRUUUURRDDLRDDLRUUUULLLLDDRLUURRDDDDLLUDUUUU

result:

ok Valid Solution (Length = 114).

Test #13:

score: 0
Accepted
time: 3ms
memory: 28052kb

input:

4 5
11111
10000
11111
00001
1 3 4 5

output:

RRLLLLDDRRRRDULLLLUURRLLDDRRRRDDRRRRDDLLRRUULLLLUDRRRRDDLLLLRR

result:

ok Valid Solution (Length = 62).

Test #14:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

3 5
10100
00010
00111
1 3 1 1

output:

-1

result:

ok No Solution.

Test #15:

score: 0
Accepted
time: 3ms
memory: 27836kb

input:

4 5
10001
11111
11100
11111
4 5 3 1

output:

DLLUURRUDLLLDDLUUUDDDRUURDDRRULLLLRRRRRRRRLLLLURRDDRUURDDDUUULDDLLLDURRUULLD

result:

ok Valid Solution (Length = 76).

Test #16:

score: 0
Accepted
time: 3ms
memory: 27836kb

input:

3 5
11111
10100
11111
1 2 3 5

output:

RRDLULRDDRRLLLLUUDDRRUURRLLLRDDRRRRDDRLLLRRUURRDDUULLLLRRDDRLULDRR

result:

ok Valid Solution (Length = 66).

Test #17:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

4 5
01110
10101
11011
10111
1 3 2 3

output:

-1

result:

ok No Solution.

Test #18:

score: 0
Accepted
time: 3ms
memory: 27884kb

input:

5 5
11111
11111
11111
11111
11111
1 3 5 2

output:

LLLRRDDDDRUUUURDDDDUUUULDDDDLLUUUULDDDDUUUURDDDDRUUUUDDDDLLLRRRRRRRRLLLDDDDUUUURDDDDRUUUUDDDDLUUUULLDDDDLUUUUDDDDRUUUURDDDDRRLLL

result:

ok Valid Solution (Length = 128).

Test #19:

score: 0
Accepted
time: 3ms
memory: 28016kb

input:

5 5
11111
10101
11111
10101
11111
5 1 2 3

output:

DLLUUUURRDDDDRRUUUULRDDLRDDLLLRUULRUULLDDDDULDLRUURRRRRRUURLDLUDDDDLLUURLUURLLLDDRLDDRLUUUURRDDDDRRUUUULLD

result:

ok Valid Solution (Length = 106).

Test #20:

score: 0
Accepted
time: 3ms
memory: 28056kb

input:

5 5
11111
10000
11111
00001
11111
4 5 5 3

output:

ULLDDRRRRDULLLLUURRRRLLLLDDRRRRDDLLLLRRRRULLDDLLURRRRLLLLDDRRRRDDLLLLRRRRUULLLLUDRRRRDDLLU

result:

ok Valid Solution (Length = 90).

Test #21:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

5 5
01010
10101
10101
11001
10011
4 1 5 4

output:

-1

result:

ok No Solution.

Test #22:

score: 0
Accepted
time: 0ms
memory: 27824kb

input:

5 5
10101
11111
10101
11111
11111
3 1 2 4

output:

DLUUUDRRUDDDDRURUUUDLRDDDULDLLULDURDRUUULLDDLRUUUDRRRRRRDUUURLDDLLUUURDRUDLULLDLUDDDRLDUUURURDDDDURRDUUULD

result:

ok Valid Solution (Length = 106).

Test #23:

score: 0
Accepted
time: 3ms
memory: 28052kb

input:

5 5
00001
11111
01110
01111
01111
1 5 5 2

output:

DLDDDRUDLLUUULDDDUUULRRDDDRUUURULLDLDDDRRDDDLDLLURUUURDDDRRLUUUDDDLUUULLDURDDDLD

result:

ok Valid Solution (Length = 80).

Test #24:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

5 5
01011
10111
11011
10101
01110
4 1 2 3

output:

-1

result:

ok No Solution.

Test #25:

score: 0
Accepted
time: 7ms
memory: 27832kb

input:

10 8
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
11111111
7 7 3 6

output:

UUUUUUUDDDDDDRRRRRLUUUUUURDDDDDDDDDLUULUUUUUUULDDDDDDDDDRUDLLUUUUUUUUULDDDDDDDDDLUUUUUUUUULDDDDDDDDDUUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDRDDRUUUUUUUUULDDDDDDUUUUUUUDDDDDDDDDLLRRRRRRLLDDDDDDDDDUUUUUUUDDDDDDLUUUUUUUUURDDRDDDDDDDRUUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDDDRUUUUUUUUUDDDD...

result:

ok Valid Solution (Length = 396).

Test #26:

score: 0
Accepted
time: 0ms
memory: 27828kb

input:

10 6
111111
101010
111111
101010
111111
101010
111111
101010
111111
101010
1 6 2 3

output:

UUUUUUULDLURLDDDDDDDDDURLLLUUUUUUUURLLLDDDDDDDDDURLUURLUURLUURLUURRDDRLDDRLDDRLDDDURRUURLUURLUURLUURUUUUUUULDDDDDDDDDLUDDULDDDDDDDDDLUUUUUUURUULRUULRUULRUURRUDDDLRDDLRDDLRDDRRUULRUULRUULRUULRUDDDDDDDDDLLLRUUUUUUUULLLRUDDDDDDDDDLRULDLUUUUUUU

result:

ok Valid Solution (Length = 240).

Test #27:

score: 0
Accepted
time: 3ms
memory: 27832kb

input:

10 10
1111111111
1000000000
1111111111
0000000001
1111111111
1000000000
1111111111
0000000001
1111111111
1000000000
5 5 5 2

output:

RUULLLLLLLLLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDURRRRRRRRRUULLLLLLLLLUURRRRRUULLLLLLLLLUUDDRRRRRRRRRUDDLLLLLLLLLDDLLLLLLLLLDDURRRRRRRRRDDUULLLLLLLLLUURRRRRUULLLLLLLLLUURRRRRRRRRUDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLRRRRRRRRRUULLLLLL...

result:

ok Valid Solution (Length = 328).

Test #28:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

10 10
1010110101
0000011010
1001001001
0011111000
1000111100
1011101001
1100110011
0110001011
0011111000
0101011101
7 5 4 3

output:

-1

result:

ok No Solution.

Test #29:

score: 0
Accepted
time: 0ms
memory: 27820kb

input:

10 6
100100
111111
100001
111111
101111
111111
101010
111111
111100
111111
6 5 7 3

output:

DDDULLULDRUURUULLUDLLLUDDDDDDDDDRUURUUUURDDUULLRDDLRDDDDRUURUDRLLDDRRLLLUULDDLUUUUUUUURRRRRDDDDUULDDUUUDDDLLDLDDRRRRDDLDLLDDDUUUDDLUUDDDDRRRRRUUUUUUUULDDLUULLLRRDDLLRDURUURDDDDRLDDRLLUUDDRUUUURUURDDDDDDDDDULLLDULLUURUURDLULLUDDD

result:

ok Valid Solution (Length = 228).

Test #30:

score: 0
Accepted
time: 0ms
memory: 27908kb

input:

10 8
11111110
11110111
01111111
11111101
11011101
11111111
11111011
11011101
11001111
11111110
7 1 2 1

output:

LUUUUULLUDDDLLUUURUUURDDDRUUURRDDDDDRDRUUUUULUDDURDDDDDDDLDLUULUUUUUDDLDDDULULUDDDDDRRRUDLLLLUUDDRUUUURDRUURDDDRDDRURUULULUUUUULLDDDLUUULLDURDDDLDDDDDDLULLLLLDLRRUUUUUURURRRRRRURUUUUUURRLDLLLLLULDDDDDDLDDDRUDLLUUULDDDLLUUUUULULUURURDDRDDDRUURDRUUUURDDUULLLLDURRRDDDDDULULUDDDLDDUUUUULUULDLDDDDDDDRUDD...

result:

ok Valid Solution (Length = 346).

Test #31:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

10 10
1111011101
1110111110
1111011111
1011101111
0101010111
1110111111
0111010111
1011111011
0111010101
1011111110
2 6 7 4

output:

-1

result:

ok No Solution.

Test #32:

score: 0
Accepted
time: 3ms
memory: 27840kb

input:

8 10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
8 10 6 10

output:

DDDDDRRRRRRRRRUUUUUUULDDDDDDDLUUUUUUULDDDDDDDLUUUUUUULDDDDDDDLUUUUUUULDDDDDDDLUUUUUUULDDDDDDDUUUUUUURDDDDDDDRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDUUDDDDUUDDDDDDDRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDRUUUUUUUDDDDDDDLUUUUUUULDDDDDDDLUUUUUUULDDDDDDDLU...

result:

ok Valid Solution (Length = 352).

Test #33:

score: 0
Accepted
time: 7ms
memory: 27904kb

input:

10 10
1111111111
1010101010
1111111111
1010101010
1111111111
1010101010
1111111111
1010101010
1111111111
1010101010
3 5 9 1

output:

LDRUURRDDDDDDDDDURRUUUUUUUURLLRDDRLLRDDRLLRDDRLLRDDDURLLLLLUUUUUDRLLLUUUURLLLDDDDDDDDDURRUUUDRLLRDDDURLLLUUUURLUURLUURRDDRLDDRRDDRLDDDURRUUUUUULRUULLDDUDDDDDDDDLLLLLLLLURRRRDDRRRRULLLLLLLLDDDDDDDDUDDLLUURLUUUUUURRUDDDLRDDRRDDLRDDRRUULRUULRUUUULLLRUDDDRLLRDUUURRUDDDDDDDDDLLLRUUUULLLRDUUUUULLLLLRUDDDR...

result:

ok Valid Solution (Length = 348).

Test #34:

score: 0
Accepted
time: 7ms
memory: 27812kb

input:

10 10
1111111111
1000000000
1111111111
0000000001
1111111111
1000000000
1111111111
0000000001
1111111111
1000000000
5 4 7 2

output:

LLLLLLLLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDURRRRRRRRRUULLLLLLLLLUURRRLLLLLLLLUUDDRRRRRRRRRUDDLLLLLLLLLDDLLLLLLLLLDDURRRRRRRRRDDUULLLLLLLLRRRUULLLLLLLLLUURRRRRRRRRUDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLRRRRRRRRRUULLLLLLLLLUURRRRRRRRR...

result:

ok Valid Solution (Length = 310).

Test #35:

score: 0
Accepted
time: 1ms
memory: 3496kb

input:

9 10
1111001000
1110010111
0001001000
0101000101
1101000001
0111100110
0010010000
0001001000
1011001101
2 8 5 2

output:

-1

result:

ok No Solution.

Test #36:

score: 0
Accepted
time: 3ms
memory: 27904kb

input:

5 10
1001011101
1111111111
1000011001
1111111111
1101110010
4 3 4 7

output:

DDDLRURDRURUUURDDDRRDURUUUDLLUDRRDDLLLUUULDLLUDLLLUDDDDRUDLUUURRRRRDDDULDLULDRUDLLURRRRRDDRRRRRULLDURDLULDLUDDDRRRRRUUULDURDDDDULLLDULLDLUUULLLDDRRDULLDUUURUDRRDDDRUUURURDRURLDDD

result:

ok Valid Solution (Length = 178).

Test #37:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

7 10
1111111001
1111101110
1111011111
1101011101
1111011111
1111001011
1111111011
7 10 7 2

output:

-1

result:

ok No Solution.

Test #38:

score: 0
Accepted
time: 0ms
memory: 27912kb

input:

9 10
0101011101
1111111111
0101111111
1111111111
1111110101
1011111111
1101111101
1111111011
1101011111
3 7 7 10

output:

DDLDRRRRRRURDUUURDDDDDDLULUUUUUDLDDDDDDRUDDRUDRRURUUUUUUUDLDDUURDDDDLRDDDULDLLLULLUUUUUUUDLLUDDDDRUDDULLUDDDDDRUUDRLDLUUUURUUULRRRDDDDDDDURUUUUUURDDRLDDRDRUUUUUULDDURRUDDRDDDDDDDDDDRDDURRUDDLUUUUUURDRDDLRDDRUUUUUURUDDDDDDDRRRLUUURUUUULDLRDUURDDDDDULLUDDURDDDDULLDUUUUUUULLULLLDLUDDDRLDDDDRUUDDLDUUUUU...

result:

ok Valid Solution (Length = 352).

Test #39:

score: 0
Accepted
time: 7ms
memory: 27932kb

input:

10 10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
9 5 3 2

output:

DDULLLLLLLLRRRRUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDDDUUUUUUUUULDDDDDDDDDLUUUUUUUUULDDDDDDDDDLLLUUUUUUUUULDDDDDDDDDLUUUUUUUUULDDDDDDDDDUUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDDDRRUUUUUUUUULDDDDDDDDUUUUUUUDDDDDDDDLLLLLLLLRRRRRRRRRRRRRRRRRRLLLLLLLLDDDDDDDDUUUUUUUDDDDDDDDLUUUUUUUUURRDDD...

result:

ok Valid Solution (Length = 490).

Test #40:

score: 0
Accepted
time: 3ms
memory: 27912kb

input:

10 10
1111111111
1010101010
1111111111
1010101010
1111111111
1010101010
1111111111
1010101010
1111111111
1010101010
2 1 1 3

output:

UUUUUUUULDLURRDDDDDDDDDURRUUUUUUUURRDDDDDDDDDURRUUUUUUUURLLRDDRLLRDDRLLRDDRLLRDDDURLLLLRUULRUULRUULRUULLLRDDLRDDLRDDLRDDDULLLLUUUUUURLDDRLDDRLDDDURRUUUUUUUULLDUUUUUUUULLLLLLUDDDDDDDDRRRRRRRRDDRRRRRRRRDDDDDDDDULLLLLLUUUUUUUUDLLUUUUUUUURRUDDDLRDDLRDDLRUUUUUULLLLUDDDRLDDRLDDRLDDRLLLUURLUURLUURLUURLLLLR...

result:

ok Valid Solution (Length = 382).

Test #41:

score: 0
Accepted
time: 3ms
memory: 27900kb

input:

10 10
1111111111
1000000000
1111111111
0000000001
1111111111
1000000000
1111111111
0000000001
1111111111
1000000000
7 4 3 5

output:

LLLLLRRRRRRRRRDDLLLLLLLLLDURRRRRRRRRUULLLLLLLLLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRLLLLLRUURRRRRRRRRUUDDLLLLLLLLLUUDRRRRRRRRRUDDURRRRRRRRRDUULLLLLLLLLDDUURRRRRRRRRUURLLLLLRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLRRRRRRRRRUULLLLLLLLLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRUDLLLLL...

result:

ok Valid Solution (Length = 320).

Test #42:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

10 10
1110000101
1100110001
1011011001
0000000111
0010010111
0100111011
1110010011
1100111111
0110001110
0100000101
9 9 6 10

output:

-1

result:

ok No Solution.

Test #43:

score: 0
Accepted
time: 3ms
memory: 27876kb

input:

10 10
1110111011
1111111111
1110110000
1111111111
1010011100
1111111111
1111001110
1111111111
1001010011
1111111111
6 9 2 9

output:

DRRRUUUDDDDRUUDDLLLLUURUUUURDDDDUUUURRLLLLUUURDRRURDULDLLULLDDDLLUUULDDDLUUUDDDDDDDDDRRRUUUURRUDLLLUDDDLUUDDRUURDDRLDDRLLLLUUUUUURUUURDRLDDRRUUURDDDRDDDDLDDRRRUUUURLRRRUUUULUUDDDLLLURUDDDDURULLLDDDUULUUUURRRLRUUUURRRDDLDDDDRDDDRUUURRDDLRDRUUURUUUUUULLLLRDDLRDDRUURDDUULDDDULLLDURRUUUURRRDDDDDDDDDUUUL...

result:

ok Valid Solution (Length = 372).

Test #44:

score: 0
Accepted
time: 7ms
memory: 28072kb

input:

10 10
1111110011
1011111110
0111011111
1101101101
1111111110
1110111101
1011011111
1111111101
1011111101
1111111011
7 3 5 5

output:

LULDDRDLUURUUUURDRUDDRURDDDDDDDLUUUUUDLDDDDDRLLUULUDDDLUULLUUUURURUULLDURRDDLDDDUULDDDDDDRLUURRDDRUURDDRUUUULUUDDRURDDDDRUURRUDDDDLRUUULLUURLUURUURLDDRDULLULDLULULDDDDLDDLLLDRRUURULLRRRUUURDDDDDDRUUURRRLLURUURRDLLLDDLDDDDLULULDLULLUDRDDLRUURUULRUULLUUURLDDDDURRUURDDDDRURDDUULUUUURDDRUURDDRRUULRDDDDD...

result:

ok Valid Solution (Length = 384).

Test #45:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

10 10
1101011101
1110111011
0101110101
1111101011
1111111111
1010111010
0111111101
1111101011
0111111101
1011101111
3 8 2 2

output:

-1

result:

ok No Solution.

Test #46:

score: 0
Accepted
time: 3ms
memory: 27924kb

input:

20 12
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
111111111111
16 8 13 12

output:

DDDDDDDDDDDDUUUURRRRRRRRRRRLLLLUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDLLUUULUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDRUUDDLLUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUULDDDDDD...

result:

ok Valid Solution (Length = 1062).

Test #47:

score: 0
Accepted
time: 10ms
memory: 27896kb

input:

20 17
11111111111111111
10101010101010101
11111111111111111
10101010101010101
11111111111111111
10101010101010101
11111111111111111
10101010101010101
11111111111111111
10101010101010101
11111111111111111
10101010101010101
11111111111111111
10101010101010101
11111111111111111
10101010101010101
111111...

output:

UUUUUUULDLURRUUUUUURRDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDULRUULRUULRUULRUULRUULRUULRUULRUULRUULLLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDDULLLRUULRUULRUULRUULRUULRUULRUULRUULRUULLLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDDULLLLUUUUUUUUUUUDRLLLU...

result:

ok Valid Solution (Length = 1172).

Test #48:

score: 0
Accepted
time: 7ms
memory: 27932kb

input:

20 19
1111111111111111111
1000000000000000000
1111111111111111111
0000000000000000001
1111111111111111111
1000000000000000000
1111111111111111111
0000000000000000001
1111111111111111111
1000000000000000000
1111111111111111111
0000000000000000001
1111111111111111111
1000000000000000000
11111111111111...

output:

LLLLLLLUURRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRR...

result:

ok Valid Solution (Length = 1106).

Test #49:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

20 16
0101001111110001
0000111101001011
0000111100011001
1101110100110100
1011011110001101
1101000110111111
0111010111100101
1101101111011001
1101010100000101
1111001000110010
0001011000101000
0101111010110110
0001101111000111
1010100010000110
0100100011011100
0100100101011111
0001000001001110
10011...

output:

-1

result:

ok No Solution.

Test #50:

score: 0
Accepted
time: 12ms
memory: 28184kb

input:

20 18
100101011111011110
111111111111111111
101111101010000001
111111111111111111
110010011011001010
111111111111111111
110110111110000010
111111111111111111
100001000001111000
111111111111111111
100010100111111000
111111111111111111
111100011010110111
111111111111111111
111101010111011110
111111111...

output:

URRRRRRRDRLURDDLDDRDDLLUUUUUULUUUURRUUUURUULULDLULDLLULDDDDDDDRDDDDRUUUURDDDDDDDDRUUDDDDDDRRRLLLLLLUURRLLLLUUUURUUUULDDLDDLUULUURRLLLUURUURUURUUURDULLDLDDLUUUDLDDDDDDLUULLUURUURUDDDUULLLUDDDDDDDDDDDDDDDDDDDRUURUUUUUURDDDDDDDDRRRUURUUUDRLLLUURLLRDDDDLRUULRRRDDDDRRUDRLLLUURLLDDLLLLUDRUUUUUUUURUULLLRRR...

result:

ok Valid Solution (Length = 1202).

Test #51:

score: 0
Accepted
time: 9ms
memory: 27992kb

input:

20 16
1110111111111111
1111111001111111
1111110111111011
1111110011111111
1111111111011111
1111110111101111
1111011111111111
1101111111111111
1011111111111001
0111111011111111
1110111111111111
1111111111111111
1111011011111111
0101110111111111
1110111101111110
1111111111111111
1111111111011111
11111...

output:

DDDDDDDDRDLLLULRDDDDDDDDDDDDDDDDDDDRUURUUUUUUUUUUURUUUUUURDRURDDDDDDDDDDDDDLUUUULDDDDDDDDDDRUUUUUDRDDDUUULDDDDLLLRRUULUUUUUUUUUURUUUURUDDDDDUUUULDDDDLDDDDDDDDDDRUUUUUUUURDDDDRUUUUUUUUUUUUULDLULLDDDDULUUUDDDRUUURDDDDDDLLUDDDDDDDDDDUUUUUUUUURDDDDDDDDDDDLDDLLUUUULUURUUUUUUUUUUULRDDLDDDDLUULUUUUUURDURLL...

result:

ok Valid Solution (Length = 1274).

Test #52:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

20 18
110111110101110101
101010111110101010
110101111101111101
111011111011101111
010111110111111101
111011111011111011
011111110111010111
101110101010111010
010111110101110111
101010101011101110
011101110111011111
101010111011111010
010101111111110101
101011101110111011
110101011101010101
101010101...

output:

-1

result:

ok No Solution.

Test #53:

score: 0
Accepted
time: 11ms
memory: 28168kb

input:

14 20
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
...

output:

DDDDDDDDDDDDDLLLLLLLRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUUUUUDDDDDDDDDDDDDL...

result:

ok Valid Solution (Length = 1210).

Test #54:

score: 0
Accepted
time: 12ms
memory: 28156kb

input:

19 20
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
...

output:

RDDDDDDDDDLLLLLDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUURLLRDDRLLRDDRLLRDDRLLRDDRLLRDDRLLRDDRLLRDDRLLRDDRLLRDDRLLLLRUULRUULRUULRUULRUULRUULRUUL...

result:

ok Valid Solution (Length = 1288).

Test #55:

score: 0
Accepted
time: 4ms
memory: 27824kb

input:

10 20
11111111111111111111
10000000000000000000
11111111111111111111
00000000000000000001
11111111111111111111
10000000000000000000
11111111111111111111
00000000000000000001
11111111111111111111
10000000000000000000
5 6 8 20

output:

LLLLLURRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDURRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLUURRRRRLLLLLUDDRRRRRRRRRRRRRRRRRRRUDDLLLLLLLLLLLLLLLLLLLDDLLLLLLLLLLLLLLLLLLLDDURRRRRRRR...

result:

ok Valid Solution (Length = 538).

Test #56:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

18 20
11011110100011011100
01100010001011110000
11100110001011101110
10110111100011001111
10100011111011110011
00001010110000010010
01101101100110010001
10001000111110000100
11000011001000001001
10101011101010100110
01111011011010100001
00010110000101101011
10110101011011000011
00110010111011000100
...

output:

-1

result:

ok No Solution.

Test #57:

score: 0
Accepted
time: 20ms
memory: 27924kb

input:

20 20
10101101000110011011
11111111111111111111
10110101010011101111
11111111111111111111
11010000010101011110
11111111111111111111
10100110101011011011
11111111111111111111
10010101101010101001
11111111111111111111
11101001101101101010
11111111111111111111
11100110110111110111
11111111111111111111
...

output:

DLLDDDDDDDDULLLLLLLLLLDDDDDULUUUUUUUUUUURUUUURRURDDDRUURDDRDDDDRUUUUUUULDURDRDDDDRUUUUURDDDUUULDDDDDDDRUUDDDDLDDDDDDDDDDRUUUUUUUUDDDDDDDDLLLLUURUUUURUULUUUDRLLLUULUUUDRLLDDDDRDDDDDDDDRUUUUUUUDRDDDDUUUULDDDDDDDDLLLUURUUUUUULUULUUUURUULRDDLDDRLLRDDDDLDDDDDDDDRLLLLLLLLLLUUUUUUUUUUUUUUUUUUUDRRUDDDRUURUR...

result:

ok Valid Solution (Length = 1406).

Test #58:

score: 0
Accepted
time: 11ms
memory: 27932kb

input:

18 20
11111111111110111111
01111111111011111111
01111111111110011111
11111111111101111111
11111011111110111111
11111111111110111110
11111111111111011111
11011111111111111110
11110111111111001111
10111111110110111111
11111011111111111111
11111111111011101111
11101111001111111111
11111111111111111111
...

output:

LLLLLLLLDDDRRDDDDDDDDDDDUURUURDDDDRURUUUURUUUUUUUULUURUULLDDDDDDDDRUUUDDDDDLDDDDUUULUUUUUUUUUUULDDDDDDDDDDDLUUUUUUUUUUULDDDDDDDDDDDDDDDDDRUUUUUDDDDRDULDLLUUUUUULUURUUUULUUUUURDDDUUULLDDDDDDDDDDDLUUULUUUUUUUURDDDDDDUUUUUULLRDDDLDDDDDDDDDDDDDDRUUUUUUUDDRDDDRUURUDDULDDLUUULDDDDDRRRUDLLLLUUUUUUUUUUUUUUR...

result:

ok Valid Solution (Length = 1408).

Test #59:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

13 20
11011101111111110111
11111110111010111111
11111111111101011101
10111010101111111010
01011101111111010111
10101011101110101110
01111101010101011111
11111011111110101011
11110111111111011111
11111010101011101011
01111111110101011111
10111010101011111110
11111111110111011101
12 16 1 20

output:

-1

result:

ok No Solution.

Test #60:

score: 0
Accepted
time: 17ms
memory: 27956kb

input:

20 20
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
11111111111111111111
...

output:

UUUUUUUUUUUUUUUDDDDDDDDDDDRRRRRRRRRRRRRRRLLLLLLUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDLLUUUUUUULUUUUUUUUUUUUL...

result:

ok Valid Solution (Length = 1786).

Test #61:

score: 0
Accepted
time: 10ms
memory: 27988kb

input:

20 20
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
11111111111111111111
10101010101010101010
...

output:

ULDRRRRRRRRRRRURRUUUUUURRDDDDDDDDDDDDDDDDDDDURLLLUUUUUUUUUUUDRLLLUUUUUUUURLLLDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUDRLLRDDRLLRDDRLLRDDRLLRDDDURLLLLLUUUUUUUUUUUUUUUUUURLLLDDDDDDDDDDDDDDDDDDDURLLLUUUUUUUUUUUUUUUUUURLLLDDDDDDDDDDDDDDDDDDDURLLLUUUUUUUUUUUUUUUUUURLLLDDDDDDDDDDDDDDDDDDDURLUURLUURLUURLUURLUURLUUR...

result:

ok Valid Solution (Length = 1302).

Test #62:

score: 0
Accepted
time: 3ms
memory: 28040kb

input:

20 20
11111111111111111111
10000000000000000000
11111111111111111111
00000000000000000001
11111111111111111111
10000000000000000000
11111111111111111111
00000000000000000001
11111111111111111111
10000000000000000000
11111111111111111111
00000000000000000001
11111111111111111111
10000000000000000000
...

output:

LLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLUUDDRRRRRRRRRRRRRRRRRRRUULLLLLLLLLRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDDRRRRRR...

result:

ok Valid Solution (Length = 1542).

Test #63:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

20 20
11110100001010101100
10110001101110101000
01011110111010110000
10111001001011011100
00110111011000010101
01001111110001010010
00101001010111010111
10110100100010001000
10101010001110000010
01111111010110101011
00100101001111000101
00110001001001111000
10101110010001000010
00000100010000110000
...

output:

-1

result:

ok No Solution.

Test #64:

score: 0
Accepted
time: 14ms
memory: 28212kb

input:

20 20
11010001010100101010
11111111111111111111
11000010111011001011
11111111111111111111
10010100111100111110
11111111111111111111
11101100001110000111
11111111111111111111
11010100111101000011
11111111111111111111
11010011111100110100
11111111111111111111
10001011110000111010
11111111111111111111
...

output:

DDDLDURDDDLDRRURDRUDDDDDDDDDRUUUUDDDDLLDDRDDRLLLUULUURLLDDDDRUDLLDDRDDDDRRUUUURRDDDDRUUUUDDDDLLRUULRUULLLRDDLRDDLLLLLLLLUURUURRRLLLLUUUUUUUURDDDDDDRRRLLLUURUUUUUUUUUURUDRDDRUURUDRRUDDDDDRUUDDDDLLLLDDLLUUUUUUDDRDDUURRUURDDUULDDLLLDDDDDDRRLLUURRUURRRRUULUUUULLLDDLUULLLUDDDDDLUUUULUDLDDRLLDDDDDDRDDDDRU...

result:

ok Valid Solution (Length = 1310).

Test #65:

score: 0
Accepted
time: 20ms
memory: 27932kb

input:

20 20
11111111111101111111
11111111111111111101
11111110111110111111
11111011110111111111
11010010110111111011
11111111111111101111
11111111111111111111
11111111111111111001
11111111011110111111
11111111111111111101
11101011111111111111
11111110111111101111
11111111111111111101
10111111111111100111
...

output:

UULLLLLLLLDDLLLLLLLLRRRUUUUUUUURDDDURUURDDDDDDDDDDDDDDDRUUURUUURUUUUUUUUURDDRUUDRDDDDDDDDDDDDDDDDDDRUUUUUUUUUURUUUUUUUUURDDDDRUUUURDDDRURUULRDDDDDDDDDDDDDDDDDDDLUUUULUUUUUUURLLUUURDRUUDDLULDLDDDDRUDDDLLUUDDDDDDDRUUURDDDDRUUDDDULLDLRURUUUULDDDLUUUUURRUULUUUURDDRDDRDULDDDRLDDRDDDDRUUUUUUUUUUUUUUUUULDL...

result:

ok Valid Solution (Length = 1612).

Test #66:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

20 20
11010111110101010101
10111010101111101010
11111101111101110111
10101011111010101110
11111111110101111101
10111111111010101111
11110101010111111101
10111110101011101111
01110111011101111101
10111011101010111010
11010111011111010111
11111011101011101111
01010111011111011111
11111010111110111011
...

output:

-1

result:

ok No Solution.

Test #67:

score: 0
Accepted
time: 46ms
memory: 28116kb

input:

30 25
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
11111111...

output:

DDDDDDDDDDDDDDDDDDDDDDDDDUUUUUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDD...

result:

ok Valid Solution (Length = 3324).

Test #68:

score: 0
Accepted
time: 40ms
memory: 28116kb

input:

30 25
1111111111111111111111111
1010101010101010101010101
1111111111111111111111111
1010101010101010101010101
1111111111111111111111111
1010101010101010101010101
1111111111111111111111111
1010101010101010101010101
1111111111111111111111111
1010101010101010101010101
1111111111111111111111111
10101010...

output:

ULDDDDDRDUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDULRUULRUULRUULRUULRUULRUULRUULRUULRUULRUULRUULRUULRUU...

result:

ok Valid Solution (Length = 2428).

Test #69:

score: 0
Accepted
time: 16ms
memory: 28128kb

input:

30 25
1111111111111111111111111
1000000000000000000000000
1111111111111111111111111
0000000000000000000000001
1111111111111111111111111
1000000000000000000000000
1111111111111111111111111
0000000000000000000000001
1111111111111111111111111
1000000000000000000000000
1111111111111111111111111
00000000...

output:

LLLLLDDURRRRRRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLLLLLLDDUURRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRLLLLLLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRRRRRRDDLLLLLL...

result:

ok Valid Solution (Length = 2196).

Test #70:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

30 30
011110110001111010011111110010
011101110110100110001101010100
100100100111010000000011100101
111110001011110110101000100000
100110011100000111100111100010
110011101000111000101110011101
011000001101110100001010011100
001101101010010100111111110011
100010111001110111010110100001
000101010010110...

output:

-1

result:

ok No Solution.

Test #71:

score: 0
Accepted
time: 56ms
memory: 28008kb

input:

30 30
101011111010110011011100010111
111111111111111111111111111111
101000010010011000101010010010
111111111111111111111111111111
101010011110010001011010010101
111111111111111111111111111111
111100010110101001000001000001
111111111111111111111111111111
111101000101101001001000100001
111111111111111...

output:

URDDDDDDDDDDDDDDLDDDLLLLLLLLLLLLLLLLLLLLLLLLUUURRDDDDDDRUURDDRUURUUUUUURUURRDDRUUUURUURRUURUUUURDDDDDDDDRUURRRUUUURRDDRDDRUUUUUURRUUUUUULUUURDULLDLLUDDDDDRRUULRDDRLLLLLDDRDDRRLLLLLDDRDDLLUUUUUURRLLLLLUUUURUURURDDDDDRRUUUURRLLLUDRDDRRLLLRDDLLLUUDDLRRUUUUULDLLULDLLDDRRLLLUUULDLLUDDDDDDDRDDDDRUUUUUURUD...

result:

ok Valid Solution (Length = 2932).

Test #72:

score: 0
Accepted
time: 82ms
memory: 28300kb

input:

30 30
111111111111111101111111011011
111111100111011111111111101010
111111111111111111111111011111
111111111101111111110111111110
111111111111111011111111111111
111110111111111111111111011111
111111111111111111111111111011
111101111111011111111111111111
111111111111111111111111111111
101110111110111...

output:

URRRRRRRRRDRUUUUUUUUUUUUUUUUUUUDLLLURUUUUUUUUUUUUUUURURDDDDDDDDDDDDDDRUUUUUUUUUUUUUURDDRUURDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUDRLDDRDRUURUULRDDDDDDDDDDDDDDDDDDRUUUUUUUUUUURUUUUUUURLDDRLLDDDUUURDDRDDDDDDDDDDDDDLUUUUUUUUUDDDDDDDDDDDDDDDDRDDDDDLUUULUUUUUUUDLDDDDDDLUUUUUUUUUUUUUULUUUUUURUDDDDDUUUULDDDDD...

result:

ok Valid Solution (Length = 3554).

Test #73:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

30 30
110111011111110111011111110101
101110101010111010101011101010
011101111101011101011111010111
111110101110111111111011101110
010101110101011101010101111111
101111101011111111111110101011
111101110111010101011101010101
111011111010101010101010101111
011111011111110101011111111101
111010101111101...

output:

-1

result:

ok No Solution.

Test #74:

score: 0
Accepted
time: 34ms
memory: 28104kb

input:

21 30
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111...

output:

DDDDDDDDDDDDDUUUUUUUUUURRRRLUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDLUUUUUUUUULUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDDRUUUUUUUUDDDDDDDDLLUUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDDLUUUUUUUUUUU...

result:

ok Valid Solution (Length = 2722).

Test #75:

score: 0
Accepted
time: 23ms
memory: 27984kb

input:

21 30
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101...

output:

LLLLULLLLLLLLLLLLLLLLLDRDDDDRRDRUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUU...

result:

ok Valid Solution (Length = 2128).

Test #76:

score: 0
Accepted
time: 12ms
memory: 27960kb

input:

21 30
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
100000000000000...

output:

LLLLLLLLLLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLL...

result:

ok Valid Solution (Length = 1950).

Test #77:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

25 30
011010010110010101001110110111
000011111001111101110011010001
011011100010011000110100110000
001111001100100010111111101001
000101111100111001000000001111
001010110011101110101000010000
001010011001010000011001001001
011111010111110110101001110000
011001010011100010100101011000
100011000011110...

output:

-1

result:

ok No Solution.

Test #78:

score: 0
Accepted
time: 38ms
memory: 28000kb

input:

25 30
101100000100000111111100110011
111111111111111111111111111111
100111110101001111010001110011
111111111111111111111111111111
101101100110111111011110101110
111111111111111111111111111111
111001000110101100010101000110
111111111111111111111111111111
100000001011110010001101011010
111111111111111...

output:

URDDRRRRRRRRRRRRRRRRRRRRRRUUUUUURDDDUUULDLLLULDDDDDRRUURDDDDRUDDDDDDDDDDDDDRLLLUURUULLDDDDLUULDDDDDDDRUUURDDRUURDDRRLLUURRLLLDDLUULDDDLLULDLUUURUUUUUUUURDDRRLLUURRUURUUUURDDRDDLRUULUULLLUULUURUULLULDLULDLULDDDDDRUUUDRRUDDDDDRDDDDRRUURUDDDUURLLLUUUUUULDDUURDDDDRLDDRDDLLLLUURLLLUURRLLLUUUUUUUDLDDDDDDL...

result:

ok Valid Solution (Length = 2384).

Test #79:

score: 0
Accepted
time: 56ms
memory: 28388kb

input:

25 30
111111101111111111111111111111
111111111111111101111111110111
111111111111101111111111111111
111111111111111101101111111111
011101111111111111111111101111
111011100111111110111110111111
111111110111111111111111111111
111111111111110111111111111111
111111111111111101111111111111
111111111111111...

output:

UULLDDDDLLLLLLLLLLLLLLLDLRRRDDDDDLDUUUUURDDDDURUUURDDDDDDDDDDDDDDDDDDDDDDDDRURUUUUUUUUURUUUUUUURUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDRUUUUUUUUUURUUURDDDDDDDDDDDDDDDDDDDDDDDDRUURUUUUUUUUUUUUUUUURUUUUUURDDRUURDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUURUUUUUUUUUURUUUUUURDDDRURUUR...

result:

ok Valid Solution (Length = 3024).

Test #80:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

25 30
110101110101011111010101010111
101111101011111011111110101010
110111011101110111111101011101
101011111011101011111111111011
110111111101011111110111111111
111111111110101011111111101010
110101010101010101011111011101
101010111010101111111111101111
111101110111011101011111010111
101010101010111...

output:

-1

result:

ok No Solution.

Test #81:

score: 0
Accepted
time: 67ms
memory: 28336kb

input:

30 30
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111...

output:

UUUUUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDDDRRRRRRRRRRRRRRRRRRLLUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLUUUUUUUUUUUUUUUULUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDLLUUUUUUUUUUUUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDD...

result:

ok Valid Solution (Length = 3862).

Test #82:

score: 0
Accepted
time: 50ms
memory: 28076kb

input:

30 30
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101010101010101010
111111111111111111111111111111
101010101010101...

output:

UUUUUUUUUUUUUUUUUUUDDUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURRUUUUUUUUUUUUUUUUUUUUUUUUUUUURRDDDDDDDDDDDDDDDDDDDDDDDDDDDDDURLLRUURLLRUURLLRUURLLRUURLLRUURLLRUURLLRUURLLRUURLLRUURLLRU...

result:

ok Valid Solution (Length = 2874).

Test #83:

score: 0
Accepted
time: 21ms
memory: 28152kb

input:

30 30
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
100000000000000...

output:

RRRRRRRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLL...

result:

ok Valid Solution (Length = 3650).

Test #84:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

30 30
010110110101101010000010000110
101110000111000001001111100101
010100011111100110100001111101
101101100010111011011010001010
100101010100001011101100101100
101001111001111101101100001110
000111101010011110100001110100
111111001101000001011110000111
010000100010000100000011101000
100001010111010...

output:

-1

result:

ok No Solution.

Test #85:

score: 0
Accepted
time: 55ms
memory: 28136kb

input:

30 30
100110101011111011001000111100
111111111111111111111111111111
101001000111011110000110011110
111111111111111111111111111111
111001111110100011111000000010
111111111111111111111111111111
100111001001100000100010001101
111111111111111111111111111111
110001101000111011111010110110
111111111111111...

output:

DRLDDLLDURRRRRRURDDDDDDDLDRRRRRDDRRDDRDDRUUUUUUUUUURRUUUUUUUURRRRDDRUURUUUURLLULDDDRUDLLUUULDLLDDRRLLLUULUDLLLULDDDDDRUURDDDDDDRUURDDRLUURLLDDDDDDDDLUULLDDDDRUUDDRDDRLLLDDRLLUULUURLLLUURRUURDDUULLUUUUUURDDDDRRRRLLLLUURRUURDDUULLRDDLLUULLUUUURUUURDDDRUUDDLUUULLDLULDDDDDRDDLLLUUUURUULUDLLUDLDDDDDDDDDD...

result:

ok Valid Solution (Length = 2820).

Test #86:

score: 0
Accepted
time: 80ms
memory: 28552kb

input:

30 30
111101111111111111111011111111
100111111111111111111111011111
111111011111111111011111111110
101111111101111111111111111111
111111111111111111111111111111
111111101111011111111110111111
111011111111111111111111111111
111111111111111111111101111111
111111111111111111111111111111
011111100111111...

output:

RULLLLLLLULDDDDDDDRDLLLDLDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUURUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDRUUUUUUUUURURDDDDRUURUURDDDDDDDDDDDDRUUUUUUUUUUUURDDDDDDDDDDRUUUUUUUDDDDDDDDDDDDDDDDDDDDDDDDDDLUUUUULUURUUUUUUULULDDDDDDDDDDDDDDDRUUUUDDDDLLUUUUUUUUUULUURLLUUUUUUUUUU...

result:

ok Valid Solution (Length = 3546).

Test #87:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

30 30
011111010101111111011101111101
111011101011111110111111101011
111111010101011101111101110101
111110101011101110111111101110
010111011101110101110101111101
101111101011101110101010111111
110101010101010111011101010101
101110101111101110101110111111
110111011101010111010111110101
101011111110111...

output:

-1

result:

ok No Solution.

Test #88:

score: 0
Accepted
time: 69ms
memory: 28220kb

input:

30 30
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111...

output:

UUUUUUUUUUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDDDDDDDDDDDDRUUUUUUUUUUUUUUUUUUUUUUUUUUUUURDDD...

result:

ok Valid Solution (Length = 3940).

Extra Test:

score: 0
Extra Test Passed