QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#773093#7751. Palindrome PathCrysflyWA 205ms4280kbC++142.8kb2024-11-23 00:50:252024-11-23 00:50:26

Judging History

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

  • [2024-11-23 00:50:26]
  • 评测
  • 测评结果:WA
  • 用时:205ms
  • 内存:4280kb
  • [2024-11-23 00:50:25]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ll __int128
//#define ull unsigned long long
#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?-x:x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<ll,ll>pii;
typedef vector<int>vi;

#define maxn 500005
#define inf 0x3f3f3f3f

int n,m,sx,sy,tx,ty;
int a[33][33];

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string opt="DRUL";

bool vis[33][33],vis2[33][33];
string res;

int vis3[33][33],sum3,nd;
bool flag;

bool mov(int d){
	//cout<<"mov "<<opt[d]<<"\n";
	int sum=0;
	memset(vis2,0,sizeof vis2);
	For(i,1,n)For(j,1,m)if(vis[i][j]){
		if(!a[i+dx[d]][j+dy[d]]) vis2[i][j]=1;
		if(a[i-dx[d]][j-dy[d]]) vis2[i-dx[d]][j-dy[d]]=1;
	}
	For(i,1,n)For(j,1,m)sum+=vis2[i][j];
	if(!sum) return 0;
	memcpy(vis,vis2,sizeof vis2);
	res+=opt[d];
	if(a[sx+dx[d]][sy+dy[d]]) sx+=dx[d],sy+=dy[d];
	if(vis[sx][sy] && flag) {
		string rev=res;
		reverse(rev.begin(),rev.end());
		cout<<res+rev<<"\n";
		exit(0);
	}
//	cout<<"now "<<sx<<" "<<sy<<"\n";
//	For(i,1,n)For(j,1,m)cout<<vis2[i][j]<<" \n"[j==m];
	if(res.size()>500000){
		puts("-1");
		exit(0);
	}
	return 1;
}

bool vs[33][33];
void dfs(int x,int y){
	vs[x][y]=1;
//	cout<<"dfs "<<x<<" "<<y<<"\n";
	For(d,0,3){
		int xx=x+dx[d],yy=y+dy[d];
		if(a[xx][yy] && !vs[xx][yy]) {
			assert(mov(d^2));
			dfs(xx,yy);
			assert(mov(d));
		}
	}
}

mt19937_64 rnd(64);
void work()
{
	n=read(),m=read();
	For(i,1,n){
		string s;cin>>s;
		For(j,1,m)a[i][j]=(s[j-1]&1),nd+=a[i][j];
	}
	sx=read(),sy=read(),tx=read(),ty=read();
	vis[tx][ty]=1;
	dfs(tx,ty);
	flag=1;
	For(i,1,n)For(j,1,m){
		if(a[i][j] && !vs[i][j]){
			puts("-1");
			exit(0);
		}
	}
	memset(vis,0,sizeof vis);
	vis[tx][ty]=1;
//	cout<<"SUM3 "<<sum3<<" "<<nd<<"\n";
	while(1){
		int d=rnd()%4;
		For(_,1,max(n,m)) mov(d);
	}
}
/*

*/
signed main()
{
//	freopen("my.out","w",stdout);
	int T=1;
	while(T--)work();
    return 0;
}
/*
9 30
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
1 1 9 30
*/

詳細信息

Test #1:

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

input:

2 2
11
11
1 1 2 2

output:

DRUDLURRLLLLLLDDLLLLLLRRULDURD

result:

ok Valid Solution (Length = 30).

Test #2:

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

input:

2 2
10
01
1 1 2 2

output:

-1

result:

ok No Solution.

Test #3:

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

input:

1 1
1
1 1 1 1

output:

RR

result:

ok Valid Solution (Length = 2).

Test #4:

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

input:

5 4
1111
1111
1111
1111
1111
4 2 4 2

output:

ULLDDDDRUUUDRDDRUUUUDDDDLUULDDLUUUURRDRULLLLLLLLLLLLLLLDDDDLLLLLLLLLLLLLLLURDRRUUUULDDLUULDDDDUUUURDDRDUUURDDDDLLU

result:

ok Valid Solution (Length = 114).

Test #5:

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

input:

5 5
11111
10101
11111
10101
11111
1 4 5 5

output:

DDDDRRUUUULRRRDDLRDDLRUUUULLDDLRDDLLUUUURRRRRUUUUULLLDDDDDLLLLLRRRRRUUUDDDDUUURRRRRLLLLLDDDDDLLLUUUUURRRRRUUUULLDDRLDDLLUUUURLDDRLDDRRRLUUUURRDDDD

result:

ok Valid Solution (Length = 146).

Test #6:

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

input:

5 3
111
100
111
001
111
4 3 3 2

output:

LUURRLLDDRRDDLLRRUULRLLRLUURRLLDDRRDDLLRRUUL

result:

ok Valid Solution (Length = 44).

Test #7:

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

input:

5 4
1001
1101
1111
0011
0010
2 2 1 1

output:

UULLUUDLDDDUUURDRDURDDRRRRRUUUUULLLLLUUUUULLLLLLLLLLDDLLLLLLLLLLUUUUULLLLLUUUUURRRRRDDRUDRDRUUUDDDLDUULLUU

result:

ok Valid Solution (Length = 106).

Test #8:

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

input:

5 3
101
111
100
111
100
4 1 2 2

output:

LDURRUUUDLLRRDDDULRUUULLLLLLLLLLLLLLLDDLLLLLLLLLLLLLLLUUURLUDDDRRLLDUUURRUDL

result:

ok Valid Solution (Length = 76).

Test #9:

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

input:

5 5
01110
10110
11110
11011
11100
2 4 5 1

output:

LLRDDLLULRDDDRUDRLLUURRRUDDULUURLLLLLUUUUUDDDDDRRRRRUUUUUDDDDDDDDDDUUUUURRRRRUUUUUUUUUUDDDDDRRRRRLLLLLLLLLLLLLLLUUUUUUUUUUDDDDDDDDDDDDDDDUUUUURRRRRRRRRRRRRRRDDDDDUUUUULLLLLRRRRRUUUUUDDDDDDDDDDLLLLLLLLLLUUUUUUUUUUDDDDDUUUUUDDDDDUUUUURRRRRLLLLLUUUUUUUUUUDDDDDLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRLLLLLRRRRRUUU...

result:

ok Valid Solution (Length = 766).

Test #10:

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

input:

5 3
011
111
110
111
011
3 1 2 1

output:

UULULDURDDDLDRLURUURDDUUUUULLUUUUUDDRUURULRDLDDDRUDLULUU

result:

ok Valid Solution (Length = 56).

Test #11:

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

input:

4 5
11111
11111
11111
11111
3 2 1 3

output:

UUULLDDDRUUDDLUUURRRDDDRUUUDDDLUUULDDDRRUUUUULLLLUUUUURRDDDLUUULDDDUUURDDDRRRUUULDDUURDDDLLUUU

result:

ok Valid Solution (Length = 94).

Test #12:

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

input:

5 5
11111
10101
11111
10101
11111
2 5 1 1

output:

UUUULLLLDDDDRRUUUDLRRLDDRLLLUUUURRRRDDDDUUUUULLLLUUUUUDDDDRRRRUUUULLLRDDLRRLDUUURRDDDDLLLLUUUU

result:

ok Valid Solution (Length = 94).

Test #13:

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

input:

4 5
11111
10000
11111
00001
1 3 4 5

output:

DRRRRDDLLLLRRRRUULLLLURRRRRLLLLLLLLLLLLLLLDDDDDLLLLLRRRRRDDRRRRRLLLLLDDDDDLLLLLLLLLLLLLLLRRRRRULLLLUURRRRLLLLDDRRRRD

result:

ok Valid Solution (Length = 116).

Test #14:

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

input:

3 5
10100
00010
00111
1 3 1 1

output:

-1

result:

ok No Solution.

Test #15:

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

input:

4 5
10001
11111
11100
11111
4 5 3 1

output:

ULLLLRRDDLLDURRRUDRDULLUURRDULLLLLUUUUULDDDDDRRRRDDDDDLUUUUULLLLLUDRRUULLUDRDURRRUDLLDDRRLLLLU

result:

ok Valid Solution (Length = 94).

Test #16:

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

input:

3 5
11111
10100
11111
1 2 3 5

output:

RRDDLLRRRRUULRDDLLUULLRRRRRUUUUULLLUUUUUDDDDDRRRRRUUUUUDDDDDDDDDDUUUUURRRRRUUUUUUUUUUDDDDDRRRRRLLLLLLLLLLLLLLLUUUUUUUUUUDDDDDLLLDDDDDDDDDDUUUUURRRRRRRRRRRRRRRDDDDDUUUUULLUUUUUDDDDDRRRRRRRRRRRRRRRUUUUUDDDDDDDDDDLLLDDDDDUUUUUUUUUULLLLLLLLLLLLLLLRRRRRDDDDDUUUUUUUUUURRRRRUUUUUDDDDDDDDDDUUUUURRRRRDDDDDUU...

result:

ok Valid Solution (Length = 338).

Test #17:

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

input:

4 5
01110
10101
11011
10111
1 3 2 3

output:

-1

result:

ok No Solution.

Test #18:

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

input:

5 5
11111
11111
11111
11111
11111
1 3 5 2

output:

LLLDDDDRUUURDDDRUUURUDDDDUUULDDDLUUULDDDLUUUURRRRLLLLLLLLLLLLLLLDDDDLLLLLLLLLLLLLLLRRRRUUUULDDDLUUULDDDLUUUDDDDURUUURDDDRUUURDDDDLLL

result:

ok Valid Solution (Length = 132).

Test #19:

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

input:

5 5
11111
10101
11111
10101
11111
5 1 2 3

output:

UUULLDDDDRRRRUUUULRDDLRDDLLLLUURLUURRDDDRRRRRUURRRRRDDDRRUULRUULLLLDDRLDDRLUUUURRRRDDDDLLUUU

result:

ok Valid Solution (Length = 92).

Test #20:

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

input:

5 5
11111
10000
11111
00001
11111
4 5 5 3

output:

LLDDRRRRDDLLLLRRRRUULLLLUURRRRLLRRUUUUULLLLLUUUUULLLLLLLLLLDDDDDLLLLLRRRRRUUUUUDDDDDDDDDDUUUUURRRUUUUUUUUUUDDDDDLLLLDDDDDUUUUUUUUUURRRUUUUUDDDDDDDDDDUUUUURRRRRLLLLLDDDDDLLLLLLLLLLUUUUULLLLLUUUUURRLLRRRRUULLLLUURRRRLLLLDDRRRRDDLL

result:

ok Valid Solution (Length = 228).

Test #21:

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

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: 3616kb

input:

5 5
10101
11111
10101
11111
11111
3 1 2 4

output:

LUUURDRURDRUDDDLLUDDURRDUUULULDLULDDDDURRRRUUULLLLLLLLLLLLLLLDDDDLLLLLLLLLLLLLLLUUURRRRUDDDDLULDLULUUUDRRUDDULLDDDURDRURDRUUUL

result:

ok Valid Solution (Length = 126).

Test #23:

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

input:

5 5
00001
11111
01110
01111
01111
1 5 5 2

output:

LLLDRDDLDURRUURDDRLUULDDLUULURRRLLLLLLLLLLLLLLLDDDDDLLLLLRRRRRUUUUUDDDDDDDDDDUUUUURRRRRUUUUUUUUUUDDDDDRRRRRLLLLLLLLLLLLLLLUUUUUUUUUUDDDDDDDDDDDDDDDUUUUURRRRRRRRRRRRRRRDDDDDUUUUULLLLLRRRRRUUUUUDDDDDDDDDDUUUUUUUUUUDDDDDUUUUUDDDDDUUUUURRRRRLLLLLUUUUUUUUUUDDDDDRRRRRRRRRRRRRRRLLLLLRRRRRUUUUUDDDDDDDDDDRRR...

result:

ok Valid Solution (Length = 686).

Test #24:

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

input:

5 5
01011
10111
11011
10101
01110
4 1 2 3

output:

-1

result:

ok No Solution.

Test #25:

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

input:

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

output:

UUUUUUULLDDDDDDDDDRUUUUUUUUDDDDDDDRDRUUUUUUUUURDDDDDDDDDRUUUUUUUUURDDDDDDDDDRUUUUUUUUUDDDDDDDDDLUUUUUUUUULDDDDDDDDDLUUUUUUUUULDDDDDDDDDLULDLUUUUUUUUURRDDDDDDDRRRRRUUUUUUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLUUUUUUURRRRRDDDDDDDRRUUUUUUUUULDLULDDDDDDDDDLUUUUUUUUULDDDDD...

result:

ok Valid Solution (Length = 410).

Test #26:

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

input:

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

output:

UUUUUUUUDLLUDLRDDLRDDLRDDLRDDLRRRRRUUUUUUUUUDLRDDLRDDLRDDLRDDLLLLUURLUURLUURLUURRDDDDDDDRRRRRRRRRRUUUUUUUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDDDDDDDLLLLLLLLLLRRRRRRRRRRUUUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUUUURRUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUURRRRRRRRRRLLLLLLLLLLDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLL...

result:

ok Valid Solution (Length = 410).

Test #27:

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

input:

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

output:

LLLLLLLLDDRRRRRRRRRDDLLLLLLLLLRRRRRRRRRUULLLLLLLLLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRUDLLLLLLLLLDDRRRRRRRRRDDLRUUUUUUUUUULLLLLLLLLLUUUUUUUUUULLLLLLLLLLLLLLLLLLLLDDDDDDDDDDLLLLLLLLLLRRRRRRRRRRUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUUUURRRRRRRRRRUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDRRRRRRRRRRLLLLLLLLLLLLLLLLLLLLL...

result:

ok Valid Solution (Length = 1628).

Test #28:

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

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: 1ms
memory: 3780kb

input:

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

output:

UUULLLRRDDLLRDDLDDDDRRDURRRUUUUUUUULDDUURDDDDLLLDLDRRUDRLLLURURRRDDDDDULLLLLUUUURUURUURDDDRRRRRRRRRRUUULLLUUUUUUUUUUDDDDDDDDDDRRRRRRRRRRUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUUUURRRRRRRRRRUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDRRRRRRRRRRLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDLDDDDDDDDDDDDD...

result:

ok Valid Solution (Length = 704).

Test #30:

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

input:

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

output:

LUUUUUUUULLLLLDLDDDDDDDRURUUULUDRRUUULDURDRDDDLDDRURDDLDLLUDLRRRRRRLLLURUULDLUURURUDLUULDDLDDDLDLUUUUUUURURRRRRRDDDDDDUUUUUULDDDDDDDDRLLLLLLLLLLUUUUUUUULLLLLDDDDDDDDDDLRRRRRRRRRRUURRRRRRRRRRLDDDDDDDDDDLLLLLUUUUUUUULLLLLLLLLLRDDDDDDDDLUUUUUUDDDDDDRRRRRRURUUUUUUULDLDDDLDDLUULDURURUULDLUURULLLRRRRRRLDU...

result:

ok Valid Solution (Length = 358).

Test #31:

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

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: 0ms
memory: 3812kb

input:

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

output:

UURDDDLDDDDRUUURUUUURDDDDDLDDRURUUUUUURDDDDDDDLRRUUUUUUURDDDDDDDRUUUUUUURDDDDDDDUUUUUUULDDDDDDDLUUUUUUULDDDDDDDLUUUUUUULDDDDDDLDLUURUUUUULDDDDLDDDLUUUURUUULDDRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLUURRRRRRRRRRDDLUUURUUUULDDDLDDDDLUUUUURUULDLDDDDDDLUUUUUUULDDD...

result:

ok Valid Solution (Length = 408).

Test #33:

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

input:

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

output:

UDLLUDLLUDLLUDLLUDLRDDLRDDLRDDLRDDLRRRUUUUUUUDLRRRUDDDLRDDLRDDLRRRUUUUUUUDLRRRUDDDLRDDLRDDLRUUUUUULLDDLRDDLRDDLLUUUUUULLDDLRDDLRDDLLUUUUUUUURRRRRRRRULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLURRRRRRRRUUUUUUUULLDDRLDDRLDDLLUUUUUULLDDRLDDRLDDLLUUUUUURLDDRLDDRLDDDURRRLDUUUUUUU...

result:

ok Valid Solution (Length = 366).

Test #34:

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

input:

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

output:

LLLLLLLLUURRRRRRRRRUDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLRRRRRRRRRUULLLLLLLLLUURRRRRRRRRUULRLLLLLLLLLLRLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDURRRRRRRRRUULLLLLLLL

result:

ok Valid Solution (Length = 228).

Test #35:

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

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: 0ms
memory: 3616kb

input:

5 10
1001011101
1111111111
1000011001
1111111111
1101110010
4 3 4 7

output:

LLUDLDDDURRDRUURUURDRUDRRURDDDLLLLLDURRDURRRDUUUULDLLLULDDLDDLULLUURRRRRRRRRULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLURRRRRRRRRUULLULDDLDDLULLLDLUUUUDRRRUDRRUDLLLLLDDDRURRDURDRUURUURDRRUDDDLDULL

result:

ok Valid Solution (Length = 218).

Test #37:

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

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: 3560kb

input:

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

output:

UURDURRDDLDLLDDDDDURUURUDDDDRUUURUUUUUDRDDDDDLDDURRUUUUUUUDRRURDDLRDDLLUDDRDDLRDURLUURLLURRUUUULDLLDDDDDDDULLURUUUUULDDLRDDLDDDLUUULDDLUUUURRURUULLLDDRRRRRRRRRRUUDDDDDDDDUURRRRRRRRRRDDLLLUURURRUUUULDDLUUULDDDLDDRLDDLUUUUURULLUDDDDDDDLLDLUUUURRULLRUULRUDRLDDRDDULLDDRLDDRURRDUUUUUUURRUDDLDDDDDRDUUUUUR...

result:

ok Valid Solution (Length = 332).

Test #39:

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

input:

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

output:

UUUUUUULLLLLLLLDDDDDDDDDRUUUUUUUURDDDDDDDDRUUUUUUUURDDDDDDDDRUUUUUUUURDDDDDDDDRUUUUUUUUDDDDDDDRDRUUUUUUUUUDDDDDDDDDLULDLUUUUUUUULDDDDDDDDLUUUUUUUULDDDDDDDDLUUUUUUUULDDDDDDDDLUUUUUUUUURRRRRRRRDDDDDDDRUUUUUUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLUUUUUUURDDDDDDDRRRRRRRRU...

result:

ok Valid Solution (Length = 482).

Test #40:

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

input:

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

output:

UUUUUUUUUDLLUDLLUDLLUDLRDDLRDDLRDDLRDDLRRRUUUUUUUDLRRRUDDDLRDDLRDDLRRLUURLUURLUURLLLDDLRDDLRDDLLUUUUUUUURRRRRRRRUDDDLRDDLRDDLRDDLRUUUUUUUULLDDDDDDDDRRUUUUUUUUUURRDDDDDDDDLLUUUUUUUURLDDRLDDRLDDRLDDDURRRRRRRRUUUUUUUULLDDRLDDRLDDLLLRUULRUULRUULRRLDDRLDDRLDDDURRRLDUUUUUUURRRLDDRLDDRLDDRLDDRLDULLDULLDULL...

result:

ok Valid Solution (Length = 310).

Test #41:

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

input:

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

output:

LLLLLUURRRRRRRRRUULLLLLLLLLUURRRRRRRRRUDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLDDRRRRRRRRRDDLLLLLLLLLRRRRRRRRRUULLLLRRRRLLLLLLLLLLUUUUUUUUUULLLLLLLLLLLLLLLLLLLLDRRRRRRRRRRUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUUUURRRRRRRRRRUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUUUURRRRRRRRRRDLLLLLLLLLLLLLLLLLLLLUUUUUUUUUULLLLLL...

result:

ok Valid Solution (Length = 416).

Test #42:

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

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: 0ms
memory: 3620kb

input:

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

output:

LDRLURRRDRUUUUULUULLUULDDUURRRRDDRRUULRRRRDDLLDLDLRRDDLLDDDURRURURUUULDURDDDDDLDLRRLURUULDLDLLUURRUULURURRUULLLDDLLUULLLDDDDLRRUDDDLLRRRUDLUULUURRDDRDDDDDLULLRRRRRRRRUUUUUUUULLLLLLLLLLUUUUUUUUUULLLLLLLLDDDDDDDDDDRRRRRRRRRRDDDDDDDDDDLLLLLLLLUUUUUUUUUULLLLLLLLLLUUUUUUUURRRRRRRRLLULDDDDDRDDRRUULUULDURR...

result:

ok Valid Solution (Length = 434).

Test #44:

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

input:

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

output:

ULUUUULDLDDLLUUURLDDDDURRDDLRDDLLUDRDDLRURRUUUUUUDDDRLDDRDDRURUUURUUUUULLDDRUDDULUURRRRDDLRDDLDDDLDDLRRRUDLLUURURUDLUURUUUULLDDDDDLDLRDDLDLUULDLLURUUUUUURURDDDDRDRRRRUUUUULLLLLLLLLLUUUUUUUUUULLLLLDDDDDDDDDDLLLLLLLLLLRRRRRRRRRRUUUUUUDDDDDDDDDDDDDDDDDDDDUUUUUUUUUURRRRRRRRRRUUUUUUUUUUUUUUUUUUUUDDDDDDDD...

result:

ok Valid Solution (Length = 1314).

Test #45:

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

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: 0ms
memory: 3576kb

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:

UUUUUUURDDDDDDDDLDDDDDDDDDDDRUUUUUUUUUURUUUUUUUUURDDDDDDDDDDLDDDDDDDDDRUUUUUUUURUUUUUUUUUUURDDDDDDDDDDDDLDDDDDDDRUUUUUURUUUUUUUUUUUUURDDDDDDDDDDDDDDLDDDDDRUUUURUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDLDDDRUURUUUUUUUUUUUUUUUUURDDDDDDDDDDDDDDDDDDLDRLURUUUUUUUUUUUUUUUUUULDDDDDDDDDDDDDDDDDLDDLUUURUUUUUUUUUUUUUU...

result:

ok Valid Solution (Length = 1150).

Test #47:

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

input:

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

output:

UUUUUUUUUUUUUUDLLUDLLUDLLUDLLUDLLUDLLUDLLUDLLUDDDDDDDDDDDDDDDDDDDRRUUUUUUUUUUUUUUUUUDLRRRUDDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUDLRRRUDDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUDLRRRUDDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUDLRRLDDLRRLDDLRRLDDLRRLDDLRRLDDLRRLDDLRRRD...

result:

ok Valid Solution (Length = 1244).

Test #48:

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

input:

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

output:

LLLLLLLUURRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLUDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRR...

result:

ok Valid Solution (Length = 800).

Test #49:

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

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: 1ms
memory: 3560kb

input:

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

output:

LUULLUULRRRUUUULUUUUUULLDDRDDLDDRUDLUURUULUURRRUULLLRRRRRRDDLLRRRRUULRRRDDLRDDLLUDLLLLLUDDDRUDDDDDDDRUUUUUURURDDDLDDDDRDDLLLRRDDLRRUDDDLLLLLLLUURUDRLLDDRDRRRLLLURRRRRDRRURUUUUUULDDUURRDDDDRDDLDLRURRUURUUUULUULUULUUUDLLUDRDDLDLDRRRLLLURURUURRRUUUULUURRRDDLRDDLRDDLRDDLLRDDRRRRUUUUUUUUUULLDDDDDDDDRUUUU...

result:

ok Valid Solution (Length = 1184).

Test #51:

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

input:

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

output:

UUUUUUUUUULLLLLLLLLDLDDDRUURUDDDDLDLDDDDDDDDDDDDDRUUUUUUURDDDDRUUUUUUUUUUUUUURDDDDDDDDDDDRUUUUUUUUURUUULDURRDDDRUUURDDDDLDLLUDDDDDDDDDLRDDLLUDDLDLDRRURURDDLRRRRURUUUUUUULUUUUDLLUDDDDDDDDDDRLUURUUUUDRDULDDDRLLUUUUUURLURRDDDRRUUURUULUUUUUURDDDDRUUUURDDDDDLRDDLDDDLDDLRDDLDDDDDLRURUUURUURURUDDDLDDLDDDRU...

result:

ok Valid Solution (Length = 3422).

Test #52:

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

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: 0ms
memory: 3880kb

input:

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

output:

LLLLLLLDDDDDDDDDDDDDRUUUUUUUUUUUURDDDDDDDDDDDDRUUUUUUUUUUUURDDDDDDDDDDDDRUUUUUUUUUUUURDDDDDDDDDDDDRUUUUUUUUUUUURURDDLDDDDDDDDDDDRUUUUUUUUUURUUURDDDDLDDDDDDDDDRUUUUUUUURUUUUURDDDDDDLDDDDDDDRUUUUUURUUUUUUURDDDDDDDDLDDDDDRUUUURUUUUUUUUURDDDDDDDDDDLDDDRUURUUUUUUUUUUURDDDDDDDDDDDDLDRLURUUUUUUUUUUUULDDDDD...

result:

ok Valid Solution (Length = 1274).

Test #54:

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

input:

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

output:

UUUUUUUUULLLLLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUDLRRLDDLRRLDDLRRLDDLRRLDDLRRRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUULRRRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUULRRRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUUUUUUUUUUUUUUUUULRRRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRDDLRRRUUU...

result:

ok Valid Solution (Length = 1310).

Test #55:

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

input:

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

output:

URRRRRRRRRRRRRRRRRRRUDLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLDDRRRRRRRRRRRRRRRRRRRDDLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLUURRRRRRRRRRRRRRRRRRRUULLLLLLLLLLLLLLLLLLLURRRRRRRRRRRRRRRRRRRRUDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRUDDURRRRRRR...

result:

ok Valid Solution (Length = 582).

Test #56:

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

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: -100
Wrong Answer
time: 205ms
memory: 4280kb

input:

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

output:

-1

result:

wrong answer Solution Exists, But -1 Found.