QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#638014 | #8058. Binary vs Ternary | IllusionaryWhiteTraveler# | WA | 0ms | 3808kb | C++20 | 1.9kb | 2024-10-13 14:39:14 | 2024-10-13 14:39:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
void solve() {
string a, b;
cin >> a >> b;
int n = a.size(), m = b.size();
if (n == 1 || m == 1) {
if (n != m) cout << "-1\n";
else cout << "0\n";
return ;
}
vector <pii> ans1(0), ans2(0);
while (n > 2) {
if (a[1] & 1) {
ans1.emplace_back(1, 2);
ans1.emplace_back(2, 4);
}else {
ans1.emplace_back(2, 3);
}
for (int i = 1; i < n; i ++) a[i] = a[i + 1];
n --;
}
if (a[1] & 1) {
ans1.emplace_back(1, 2);
ans1.emplace_back(2, 3);
}
while (m > 2) {
if (b[1] & 1) {
ans2.emplace_back(1, 2);
b[1] --;
}
if (b[2] & 1) {
if (m > 3) {
if (b[3] & 1) {
ans2.emplace_back(3, 4);
}
ans2.emplace_back(1, 3);
for (int i = 3; i < m; i ++) b[i] = b[i + 1];
m --;
}else {
ans2.emplace_back(2, 3);
ans2.emplace_back(1, 3);
ans2.emplace_back(1, 2);
b[1] = '1'; m = 2;
break;
}
}else {
ans2.emplace_back(1, 3);
b[1] = 49;
for (int i = 2; i < m; i ++) b[i] = b[i + 1];
m --;
}
}
if (b[1] & 1) ans2.emplace_back(1, 2);
reverse(ans2.begin(), ans2.end());
cout << ans1.size() + ans2.size() << '\n';
for (auto [l, r] : ans1) cout << l << ' ' << r << '\n';
for (auto [l, r] : ans2) cout << l << ' ' << r << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while (T --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3808kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 18 1 2 2 4 2 3 1 2 2 4 1 2 2 4 1 2 1 2 1 3 2 3 1 3 1 3 3 4 1 3 1 2 1 3 1 2 17 1 2 2 4 1 2 2 4 1 2 2 3 1 2 1 2 1 3 2 3 1 3 3 4 1 3 3 4 1 3 3 4 1 2
result:
wrong answer S!=T after all operations (test case 2)