QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#727263 | #8058. Binary vs Ternary | woaimtw# | WA | 0ms | 3780kb | C++23 | 2.1kb | 2024-11-09 12:18:12 | 2024-11-09 12:18:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<unordered_map>
#include<stack>
using namespace std;
#define int long long
#define scanf scanf_s
typedef pair<int, int> PII;
const double ef = 1e-12;
const int INF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a, b) for(int i = a;i<=b;i++)
#define pre(i,a, b) for(int i = a;i>=b;i--)
const int N = 5e5 + 5;
string a, b;
int cnt;
int ans[600][2];
int n, m;
void cun(int x, int y)
{
ans[++cnt][0] = x;
ans[cnt][1] = y;
}
void init()
{
rep(i, 1, n) {
if (a[i] == '0') cun(i - 1, i);
}
pre(i, n, 2) cun(i - 1, i);
cun(2, 2 * n - 1);
}
void han(int le, int ri)
{
int shu = ri - le + 1;
pre(i, ri, le) cun(i - 1, i);
cun(ri, ri + shu);
}
void solve()
{
cin >> a;
cin >> b;
n = a.size();
m = b.size();
a = " " + a;
b = " " + b;
cnt = 0;
if (a == b) {
cout << 0 << endl;
return;
}
if (n == 1)
{
if (a == b) {
cout << 0 << endl;
}
else cout << -1 << endl;
return;
}
if (m == 1)
{
cout << -1 << endl;
return;
}
init();
rep(i, 3, m) {
cun(1, 2);
cun(1, 2);
}
rep(i, 2, m) cun(i - 1, i);
rep(i, 2, m)
{
if (b[i] == '0')
{
int k = i;
for (; k <= m; k++)
{
if (b[k] == '1') {
k = k - 1;
break;
}
}
han(i, k);
i = k;
}
}
if (cnt > 512)while (1);
cout << cnt << endl;
rep(i, 1, cnt) {
cout << ans[i][0] << " " << ans[i][1] << endl;
}
// cout << (a == b);
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
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: 3780kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 31 2 3 5 6 5 6 4 5 3 4 2 3 1 2 2 11 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 3 3 4 4 5 5 6 6 7 2 3 3 4 4 5 5 6 7 8 6 7 8 10 17 3 4 2 3 1 2 2 7 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 3 3 4 4 5 5 6
result:
wrong answer (l,r) is invalid (test case 2)