现在 Sub1 和 Sub2 各 WA 一个点, Sub 3 AC 了。
手算了一下 样例 #3 RRRRR
和 RRLLL
好像都是可以的(不知道有没有算错)。
#include <vector>
#include <iostream>
using lint = long long;
using vlint = std::vector<lint>;
bool operator==(const vlint &a, const vlint &b) {
if (a.size() != b.size()) return false;
for (size_t i = 0; i < a.size(); ++i)
if (a[i] != b[i]) return false;
return true;
}
bool check_solution(lint sums, lint sumt) {
if (sums >= sumt || sums == 0) return false;
for (; ; sums *= 2) {
if (sums == sumt) return true;
if (sums > sumt) break;
}
return false;
}
lint get_step(lint sums, lint sumt) {
lint res = 0;
for (; ; sums *= 2, ++res)
if (sums == sumt) return res;
return -1;
}
void change(vlint &s) { // L 操作
vlint t(s);
for (size_t i = 0; i < s.size(); ++i) {
if (i == 0) s[i] += t[s.size() - 1];
else s[i] += t[i - 1];
}
}
void move(vlint &s) { // 整体左移
vlint t(s);
for (size_t i = 0; i < s.size(); ++i) {
if (i == s.size() - 1) s[i] = t[0];
else s[i] = t[i + 1];
}
}
int main() {
int n; std::cin >> n;
vlint s(n), t(n);
lint sums = 0, sumt = 0;
for (auto &x : s) std::cin >> x, sums += x;
for (auto &x : t) std::cin >> x, sumt += x;
if (s == t) return std::cout << "null\n", 0;
if (!check_solution(sums, sumt))
return std::cout << "No solution\n", 0;
int step = get_step(sums, sumt), r = 0;
for (int i = 0; i < step; ++i) change(s);
int move_cnt = 0;
while (s != t) {
move(s), ++r;
if (move_cnt > 10 * n)
return std::cout << "No solution\n", 0;
++move_cnt;
}
for (int i = 0; i < r; ++i) std::cout << 'R';
for (int i = 0; i < step - r; ++i) std::cout << 'L';
std::cout << std::endl;
return 0;
}