QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376189 | #8058. Binary vs Ternary | Eunoiay | WA | 1ms | 3612kb | C++20 | 1.5kb | 2024-04-03 23:30:11 | 2024-04-03 23:30:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
string a, b;
cin >> a >> b;
if (a == "1" || b == "1") {
cout << (a == b ? 0 : -1) << "\n";
return;
}
int n = a.size();
int m = b.size();
vector<pair<int, int>> ans;
for (int i = 0; i + 1 < n; ++i) {
if (a[i] == '1' && a[i + 1] == '0') {
ans.emplace_back(i + 1, i + 2);
a[i + 1] = '1';
}
}
while (a.size() < b.size()) {
ans.emplace_back(n - 1, n);
ans.emplace_back(n - 1, n);
ans.emplace_back(n, n + 1);
a += '1';
}
while (a.size() > b.size()) {
ans.emplace_back(n - 2, n - 1);
ans.emplace_back(n - 1, n + 1);
a.pop_back();
}
// cerr << a << "\n" << b << "\n";
n = m;
for (int i = m - 1; i >= 0; --i) {
if (b[i] == '0') {
ans.emplace_back(n - 1, n);
ans.emplace_back(n, n + 1);
a[i] = '0';
}
--n;
}
// cerr << a << "\n" << b << "\n";
cout << ans.size() << "\n";
for (auto [x, y] : ans) {
cout << x << " " << y << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto convert = [&](string s) {
i64 x = 0;
for (char c : s) {
x = x * 3 + (c - '0');
}
string t;
while (x) {
t += x % 2 + '0';
x /= 2;
}
reverse(t.begin(), t.end());
return t;
};
/*
10
11
100
1001
11100
*/
// string tt = "110";
// for (int i = 0; i < 10; ++i) {
// cout << tt << "\n";
// tt = convert(tt);
// }
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 11 2 3 5 6 5 6 5 6 6 7 6 7 7 8 4 5 5 6 2 3 3 4 6 3 4 3 4 4 5 3 4 3 4 4 5
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3588kb
input:
1000 11100 111 1 11110 10001 10 1011 1111 10 1110 1100 11 11010 11 110 11 1 10001 10110 10 10 11111 10000 1001 10 1 11 10111 11 10 1 100 11 10100 1 10 101 11 1100 110 11 1110 1 1001 1 11111 10 10010 10 11001 110 1010 10011 1110 10100 1001 1001 101 100 1 1001 11 101 11 101 1001 1 1 1011 1 10 10 1011 ...
output:
6 3 4 4 5 3 4 4 6 3 4 4 6 -1 11 1 2 2 3 3 4 3 4 4 6 3 4 4 6 3 4 4 6 1 2 2 3 1 1 2 9 1 2 1 2 1 2 2 3 1 2 1 2 2 3 3 4 4 5 6 2 3 3 4 2 3 3 5 2 3 3 5 8 2 3 4 5 3 4 4 6 3 4 4 6 3 4 4 6 3 2 3 1 2 2 4 -1 10 1 2 4 5 3 4 4 6 3 4 4 6 3 4 4 6 1 2 2 3 10 1 2 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 10 1 2 2 3 3 4 4 ...
result:
wrong answer (l,r) is invalid (test case 1)