QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694577 | #8058. Binary vs Ternary | SSAABBEERR | WA | 0ms | 3564kb | C++20 | 2.5kb | 2024-10-31 18:13:44 | 2024-10-31 18:13:53 |
Judging History
answer
#include<bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define endl "\n"
#define ll long long
#define int long long
using namespace std;
#define pii pair<int, int>
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define pre(i, a, b) for(int i = a; i >= b; i -- )
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int N = 1e6 + 10;
int n, m, k;
int a[N], b[N];
string g(string s)
{
string res;
int w = 1, sum = 0;
pre(i, s.size() - 1, 0)
{
int ww = s[i] - '0';
ww *= w;
sum += ww;
w *= 3;
}
while(sum)
{
if(sum & 1) res += '1';
else res += '0';
sum /= 2;
}
reverse(res.begin(), res.end());
return res;
}
void solve()
{
// string s;
// cin >> s;
// cout<<s<<" ";
// cout<<g(s);
// cout<<endl;
string x, y;
cin >> x >> y;
x = " " + x;
y = " " + y;
n = x.size() - 1, m = y.size() - 1;
if(x == y)
{
cout << 0 << endl;
return;
}
if(n == 1 || m == 1)
{
if(x != y)
{
cout << -1 << endl;
return;
}
}
vector<pii>ans;
int len = n;
pre(i, n, 1)
{
if(x[i] != '0') continue;
int l = i;
while(l - 1 >= 1 && x[l - 1] == '0') l -- ;
ans.push_back({i, l});
ans.push_back({l - 1, l});
len -= (i - l);
i = l;
}
x.clear();
x += " ";
rep(i, 1, len) x += '1';
pre(i, len - 2, 1)
{
ans.push_back({i, i + 1});
}
if(len > 2) ans.push_back({2, 2 + (len - 2) * 2 - 1});
n = 2;
int now = 1;
while(n < m)
{
ans.push_back({now, now + 1});
ans.push_back({now, now + 1});
ans.push_back({now + 1, now + 2});
now ++ , n ++ ;
}
x.clear();
x += " ";
rep(i, 1, m) x += '1';
rep(i, 1, m - 1)
{
if(y[i] == '1' && y[i + 1] == '0')
{
int l = i, r = i + 1;
while(r + 1 <= m && y[r + 1] == '0') r ++ ;
pre(j, r - 1, l)
{
ans.push_back({j, j + 1});
ans.push_back({j + 1, j + 2});
}
i = r;
}
}
cout << ans.size() << endl;
rep(i, 0, 0)
{
cout << ans[i].first << " " << ans[i].second << endl;
}
}
signed main()
{
IOS;
int _;
_ = 1;
cin >> _;
while(_ -- )
{
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 30 6 6 15 2 3
result:
wrong answer (l,r) is invalid (test case 2)