forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd.cc
More file actions
64 lines (60 loc) · 1.4 KB
/
Copy pathd.cc
File metadata and controls
64 lines (60 loc) · 1.4 KB
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
// https://arc103.contest.atcoder.jp/tasks/arc103_b
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000;
ll x[N], y[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
ll p = (llabs(x[0])+llabs(y[0]))%2, m = 0;
bool ok = true;
for (int i = 0; i < n; i++) {
if (p != (llabs(x[i])+llabs(y[i]))%2) {
ok = false;
break;
}
m = max(m, llabs(x[i]) + llabs(y[i]));
}
if (ok) {
vector<ll> v;
v.push_back(1);
if (p==0) v.push_back(1);
while (v.back()*2 < m+p) v.push_back(v.back()*2);
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i < v.size() - 1) cout << " ";
}
cout << endl;
for (int i = 0; i < n; i++) {
ll l = x[i], r = y[i];
string s;
for (int j = v.size() - 1; j >= 0; j--) {
if (llabs(l) > llabs(r)) {
if (l < 0) {
l += v[j];
s.push_back('L');
} else {
l -= v[j];
s.push_back('R');
}
} else {
if (r < 0) {
r += v[j];
s.push_back('D');
} else {
r -= v[j];
s.push_back('U');
}
}
}
assert(!l); assert(!r);
reverse(s.begin(), s.end());
cout << s << endl;
}
} else cout << "-1\n";
}