QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#455275 | #8058. Binary vs Ternary | nhuang685 | WA | 0ms | 3792kb | C++20 | 1.9kb | 2024-06-26 07:39:22 | 2024-06-26 07:39:22 |
Judging History
answer
/**
* @file qoj8058-1.cpp
* @author n685
* @brief
* @date 2024-06-25
*
*
*/
#include <bits/stdc++.h>
#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbgR(...) 4242
#define dbgP(...) 420
#define dbgRP(...) 420420
void nline() {}
#endif
void solve() {
std::string a, b;
std::cin >> a >> b;
dbg(a);
if (a.size() == 1 || b.size() == 1) {
if (a == b) {
std::cout << "0\n";
} else {
std::cout << "-1\n";
}
return;
}
std::vector<std::pair<int, int>> ans;
auto query = [&](int l, int r) -> void {
ans.emplace_back(l, r);
__int128_t val = 0, mul = 1;
for (int i = r, j = 0; i >= l; --i, ++j, mul *= 3) {
val += mul * (a[i] == '1');
}
std::string b2;
while (val > 0) {
b2 += '0' + val % 2;
val /= 2;
}
std::reverse(b2.begin(), b2.end());
if (b2.empty()) {
b2 += '0';
}
a = a.substr(0, l) + b2 + a.substr(r + 1);
dbg(l + 1, r + 1, a);
};
for (int i = 1; i < static_cast<int>(a.size()); ++i) {
if (a[i] == '0') {
query(i - 1, i);
}
}
for (int i = static_cast<int>(a.size()) - 2; i >= 1; --i) {
query(i - 1, i);
}
query(1, static_cast<int>(a.size()) - 1);
for (int i = 0; i < static_cast<int>(b.size()) - 2; ++i) {
query(i, i + 1);
query(i, i + 1);
query(i + 1, i + 2);
}
for (int i = static_cast<int>(b.size()) - 1; i >= 1; --i) {
if (b[i] == '0') {
query(i - 1, i);
query(i, i + 1);
}
}
std::cout << static_cast<int>(ans.size());
for (auto [l, r] : ans) {
std::cout << l + 1 << ' ' << r + 1 << '\n';
}
dbg(b);
}
auto main() -> int {
#ifndef LOCAL
std::cin.tie(nullptr)->sync_with_stdio(false);
#endif
int t;
std::cin >> t;
// std::scanf("%d", &t);
while (t--) {
solve();
nline();
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3792kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 282 3 5 6 4 5 3 4 2 3 1 2 2 10 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6 5 6 5 6 6 7 6 7 7 8 4 5 5 6 2 3 3 4 152 3 1 2 2 6 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6
result:
wrong answer (l,r) is invalid (test case 2)