-
Notifications
You must be signed in to change notification settings - Fork 3
/
tenkici.cpp
76 lines (66 loc) · 1.28 KB
/
tenkici.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
#include <bits/stdc++.h>
using namespace std;
struct pt {
int r, c, i;
};
using vp = vector<pt>;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, r, c;
cin >> n;
vp P(n);
for (int i = 0; i < n; ++i) {
cin >> P[i].r >> P[i].c;
P[i].i = i + 1;
}
char opt;
int res = 0, k;
stringstream ss;
sort(P.begin(), P.end(), [](const pt &a, const pt &b) {
return a.r > b.r;
});
opt = 'D';
for (int i = 0; i < n; ++i) {
k = n - i - P[i].r;
if (k <= 0) continue;
res += k;
while (k--) {
ss << P[i].i << ' ' << opt << '\n';
}
}
opt = 'U';
for (int i = n; i-- > 0;) {
k = n - i - P[i].r;
if (k >= 0) continue;
k *= -1;
res += k;
while (k--) {
ss << P[i].i << ' ' << opt << '\n';
}
}
sort(P.begin(), P.end(), [](const pt &a, const pt &b) {
return a.c > b.c;
});
opt = 'R';
for (int i = 0; i < n; ++i) {
k = n - i - P[i].c;
if (k <= 0) continue;
res += k;
while (k--) {
ss << P[i].i << ' ' << opt << '\n';
}
}
opt = 'L';
for (int i = n; i-- > 0;) {
k = n - i - P[i].c;
if (k >= 0) continue;
k *= -1;
res += k;
while (k--) {
ss << P[i].i << ' ' << opt << '\n';
}
}
cout << res << '\n' << ss.rdbuf();
return 0;
}