QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346798 | #8058. Binary vs Ternary | berarchegas# | WA | 0ms | 3652kb | C++20 | 2.6kb | 2024-03-08 23:50:37 | 2024-03-08 23:50:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
const ll INF = 2e18;
string a, b;
void modify(int ini, int fim, string nova) {
a = a.substr(0, ini) + nova + a.substr(fim + 1, (int)a.size() - fim - 1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> a >> b;
if (a == b) cout << "0\n";
else if (a.size() == 1 || b.size() == 1) cout << "-1\n";
else {
vector<pii> ops;
// tirar todos os 0s
for (int i = 0; i < (int)a.size(); i++) {
if (a[i] == '0') {
int x = i;
while (x + 1 < a.size() && a[x + 1] == '0') x++;
ops.push_back({i + 1, x + 1});
modify(i, x, "0");
ops.push_back({i, i + 1});
modify(i - 1, i, "11");
}
}
// deixar a com o tamanho de b
while ((int)a.size() > (int)b.size()) {
int tam = a.size();
ops.push_back({tam - 1, tam});
ops.push_back({tam, tam + 1});
ops.push_back({tam - 2, tam - 1});
ops.push_back({tam - 1, tam + 1});
ops.push_back({tam - 2, tam - 1});
a.pop_back();
}
while ((int)a.size() < (int)b.size()) {
int tam = a.size();
ops.push_back({tam - 1, tam});
ops.push_back({tam - 1, tam + 1});
ops.push_back({tam - 1, tam + 1});
ops.push_back({tam, tam + 1});
a += '1';
}
// colocar os 0's que precisamos
for (int i = 0; i < (int)b.size(); i++) {
if (b[i] == '0') {
int x = i;
while (x + 1 < b.size() && b[x + 1] == '0') x++;
for (int j = x; j >= i; j--) {
ops.push_back({j, j + 1});
modify(j - 1, j, "100");
ops.push_back({j + 1, j + 2});
modify(j, j + 1, "0");
}
i = x;
}
}
cout << ops.size() << '\n';
for (pii x : ops) cout << x.first << ' ' << x.second << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 14 3 3 2 3 6 6 5 6 5 6 5 7 5 7 6 7 2 3 3 4 4 5 5 6 6 7 7 8 8 3 4 3 5 3 5 4 5 4 5 4 6 4 6 5 6
result:
wrong answer (l,r) is invalid (test case 2)