forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
118 lines (107 loc) · 3.1 KB
/
E.cpp
File metadata and controls
118 lines (107 loc) · 3.1 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cerr << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
int cnt[11];
int f[10111000];
int value(string s) {
memset(cnt, 0, sizeof cnt);
int last = -1;
REP(i,SZ(s)) {
if (s[i] == '.') {
++last;
++cnt[last];
}
else {
assert(s[i] == 'R');
++i;
int cur = -1;
if (s[i] == '2') cur = 1;
else if (s[i] == '4') cur = 2;
else if (s[i] == '8') cur = 3;
else if (s[i] == '3') ++i, cur = 5;
else if (s[i] == '6') ++i, cur = 6;
else {
assert(s[i] == '1');
if (i+1 < SZ(s) && s[i+1] == '6') {
++i;
cur = 4;
}
else cur = 0;
}
++cnt[cur];
last = cur;
}
}
int res = 0;
int mult = 1;
FORD(i,6,0) {
res += mult * cnt[i];
mult *= 2;
}
return res;
}
vector< pair<int, string> > all;
void update(int& x, int val) {
x = min(x, val);
}
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
freopen("e.in", "r", stdin);
freopen("e.out", "w", stdout);
REP(i,7) {
FOR(dot,0,6-i) {
stringstream ss; ss << 'R' << (1<<i);
REP(turn,dot) ss << '.';
string s = ss.str();
all.push_back(make_pair(value(s), s));
}
}
sort(all.begin(), all.end());
string s;
while (cin >> s) {
string res = "";
int need = value(s);
f[0] = 0;
FOR(i,1,need) {
if (i > 64*64) {
f[i] = f[i-64] + 2;
continue;
}
f[i] = 1e9;
for(auto p : all) {
if (i >= p.first) {
f[i] = min(f[i], f[i - p.first] + SZ(p.second));
}
}
}
while (need > 0) {
string best = "XXX";
int best_val = -1;
string best_s = "";
int minf = f[need];
for(auto p : all) {
if (p.first > need) continue;
int cur = SZ(p.second) + f[need - p.first];
if (cur > minf) continue;
string t = p.second;
if (p.first != need) t += 'R';
if (t < best) {
best = t;
best_val = p.first;
best_s = p.second;
}
}
res += best_s;
need -= best_val;
}
puts(res.c_str());
}
}