QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588394 | #8058. Binary vs Ternary | XiaoTie | WA | 0ms | 3548kb | C++17 | 2.5kb | 2024-09-25 10:24:28 | 2024-09-25 10:24:30 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#define int long long
#define endl "\n"
#define bit(x) (1LL << x)
#define inf (int)1e18
using namespace std;
typedef pair<int, int> PII;
int p = 0;
void solve()
{
string A, B;
cin >> A >> B;
if (A == "1" && B != "1") {
cout << "-1" << endl;
return;
}
B = '?' + B;
vector<PII> ans;
queue<int> pos;
const int m = B.size();
int cnt1 = 0;
for (int i = 1; i <= m ; i ++)
cnt1 += B[i] == '1';
auto c1 = cnt1;
while (A.size() && A[0] == '0') {
A.erase(A.begin());
ans.push_back({1, 1});
}
for (int i = 0; i < A.size() ; i ++) {
if (A[i] == '1')
cnt1 --;
if (A[i] == '0') {
A[i] = '1', ans.push_back({i, i + 1});
cnt1 --;
}
}
while (cnt1 > 0) {
ans.push_back({A.size() - 1, A.size()});
ans.push_back({A.size() - 1, A.size()});
ans.push_back({A.size(), A.size() + 1});
cnt1 --;
A += '1';
}
while (cnt1 < 0) {
ans.push_back({A.size() - 1, A.size()});
ans.push_back({A.size(), A.size() + 1});
A.pop_back();
cnt1 ++;
}
int res = 0;
int cnt = 0;
for (int i = 2 ; i <= m + 1 ; i ++) {
if (B[i] == '0')
cnt ++;
if (i == m + 1 || B[i] == '1') {
pos.push(cnt);
res = cnt;
cnt = 0;
}
}
for (int j = 1 ; j <= res ; j ++) {
ans.push_back({c1 - 1, c1});
ans.push_back({c1 - 1, c1});
}
int now = 1;
while (pos.size() > 1) {
auto t = pos.front();
pos.pop();
if (t == 0) {
now ++;
continue;
}
ans.push_back({now, now + 1});
ans.push_back({now, now + 2});
if (t == 1) {
ans.push_back({now + 1, now + 1});
}
else {
for (int j = 1 ; j <= t - 2 ; j ++) {
ans.push_back({now, now + 1});
ans.push_back({now, now + 1});
}
}
now += t + 1;
}
cout << ans.size() << endl;
for (auto [x, y] : ans)
cout << x << " " << y << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
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: 3548kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 14 2 3 5 6 5 6 6 7 4 5 5 6 3 4 3 4 2 3 2 4 3 3 4 5 4 6 5 5 6 3 4 3 4 4 5 4 5 4 5 5 6
result:
wrong answer S!=T after all operations (test case 2)