QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369742 | #8058. Binary vs Ternary | lizixin# | WA | 1ms | 3656kb | C++14 | 1.9kb | 2024-03-28 17:18:11 | 2024-03-28 17:18:12 |
Judging History
answer
#include <iostream>
#include <cstring>
using namespace std;
const int N = 100;
char A[N], B[N];
int n, m;
using Pair = pair<int, int>;
#include <vector>
vector<Pair> ans;
void add(int a, int b) {
ans.push_back(make_pair(a, b));
}
void sol() {
cin >> A + 1;
cin >> B + 1;
n = strlen(A + 1);
m = strlen(B + 1);
ans.clear();
if (n == 1) {
if (m == 1) {
cout << "0\n";
} else {
cout << "-1\n";
}
return;
}
if (m == 1) {
cout << "-1" << '\n';
return;
}
if (A[n] == '0') {
int idx = n;
while (idx > 1 && A[idx] == '0' && A[idx - 1] == '0') idx --;
if (idx != n) { // ..100..0. -> ..10
add(idx, n);
}
n = idx;
add(n - 1, idx); // ....10 -> ....11
A[n] = '1';
}
int cnt1 = 0;
for (int i = n; i > 0; --i) {
if (A[i] == '0') { // ...0111 -> ...111
add(i, i + 1);
} else if (A[i] == '1') {
cnt1 ++;
}
}
n = cnt1;
for (int i = 1; i <= cnt1; ++i) {
A[i] = '1';
}
A[n + 1] = 0;
// cout << " --- " << cnt1 << '\n';
for (int i = 1; i <= cnt1 - 2; ++i) { // 111 -> 11
add(1, 2);
add(2, 4);
}
n = 2;
for (int i = 1; i <= n; ++i) {
A[i] = '1';
}
A[n + 1] = 0;
for (int i = m; i > 2; --i) {
add(1, 2);
add(1, 3); // +0
if (B[i] == '1') { // +1
add(2, 3);
}
}
if (B[2] == '0') {
add(1, 2);
add(2, 3);
}
cout << ans.size() << '\n';
for (auto x : ans) {
cout << x.first << ' ' << x.second << '\n';
}
}
int main() {
ios::sync_with_stdio(0);
int T;
cin >> T;
while (T --) {
sol();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3656kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 20 5 6 3 4 1 2 2 4 1 2 2 4 1 2 2 4 1 2 1 3 1 2 1 3 2 3 1 2 1 3 1 2 1 3 2 3 1 2 1 3 16 1 2 2 4 1 2 2 4 1 2 1 3 2 3 1 2 1 3 2 3 1 2 1 3 2 3 1 2 1 3 2 3
result:
wrong answer S!=T after all operations (test case 2)