QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414864 | #8058. Binary vs Ternary | kevinshan# | WA | 0ms | 3588kb | C++17 | 2.3kb | 2024-05-19 23:03:34 | 2024-05-19 23:03:36 |
Judging History
answer
#pragma GCC optimize("Ofast,O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
const int xm[4] = {-1, 1, 0, 0};
const int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll POW = 9973;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int t; cin>>t;
while(t--){
string a;
string b;
cin>>a>>b;
if(a.size() == 1 && b.size() == 1) {
cout<<0<<"\n";
}
else if(a.size() == 1) {
cout<<-1<<"\n";
}
else if(b.size() == 1) {
cout<<-1<<"\n";
}
else {
// first reduce a
int sz = a.size();
int bk;
vector<pair<int, int>> mv;
for(int i=a.size()-1; i>=0; i--){
if(a[i] == '1') {
bk = i;
break;
}
}
mv.pb({bk+2, a.size()});
sz -= sz - 2 - bk;
for(int j=sz-3; j>=1; j--) {
if(a[j] == '0') {
mv.pb({j+1, j+2});
}
else {
mv.pb({j+1, j+2});
mv.pb({j+2, j+4});
}
}
// string should be 10
mv.pb({1,2});
// now string is 11
int c = 2;
while(c<b.size()) {
mv.pb({c-1,c});
c++;
mv.pb({c-2, c-1});
mv.pb({c-1,c});
}
for(int i=b.size()-1; i>=1; i--){
if(b[i] == 0) {
mv.pb({i,i+1});
mv.pb({i+1,i+2});
}
}
cout<<mv.size()<<"\n";
for(auto p:mv) cout<<p.f<<" "<<p.s<<"\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 22 6 6 4 5 5 7 3 4 2 3 3 5 1 2 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6 5 6 5 6 6 7 18 5 4 3 4 4 6 2 3 3 5 1 2 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6
result:
wrong answer (l,r) is invalid (test case 2)