-
Notifications
You must be signed in to change notification settings - Fork 0
/
2873.cpp
101 lines (89 loc) · 2.29 KB
/
2873.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<iostream>
#include<algorithm>
#define N 1005
using namespace std;
int map[N][N];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n, m, i, j;
cin >> n >> m;
for(i=0; i<n; i++){
for(j=0; j<m; j++)
cin >> map[i][j];
}
if(n%2==1){
for(i=0; i<n; i++){
for(j=0; j<m-1; j++){
if(i%2==0) cout << "R";
else cout << "L";
}
if(i!=n-1) cout << "D";
}
}
else if(m%2==1){
for(i=0; i<m; i++){
for(j=0; j<n-1; j++){
if(i%2==0) cout << "D";
else cout << "U";
}
if(i!=m-1) cout << "R";
}
}
else{
int e=map[0][1], ex=0, ey=1;
for(i=0; i<n; i++){
for(j=0; j<m; j++){
if((i+j)%2==0) continue;
if(i==0 && j<2) continue;
if(i==n-1 && j==m-1) continue;
if(e>map[i][j]){
e=map[i][j];
ex=i;
ey=j;
}
}
}
for(i=0; i<n; i++){
if(ex==i || ex==i+1){
for(j=0; j<m-1; j++){
if(ey==j){
cout << "R";
continue;
}
if((j%2==0 && j<ey) || (j%2==1 && j>=ey)) cout << "D";
else cout << "U";
cout << "R";
}
i++;
if(ey!=m-1)
cout << "D";
if(i!=n-1){
cout << "D";
for(j=0; j<m-1; j++) cout << "L";
i++;
}
if(i!=n-1)
cout << "D";
}
else{
for(j=0; j<m-1; j++)
cout << "R";
if(i!=n-1){
cout << "D";
i++;
for(j=0; j<m-1; j++)
cout << "L";
if(i!=n-1)
cout << "D";
}
}
}
if(i<n){
for(j=0; j<m-1; j++)
cout << "R";
}
}
return 0;
}