QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#338252 | #8058. Binary vs Ternary | YMH_fourteen | WA | 0ms | 3628kb | C++14 | 1.2kb | 2024-02-25 19:42:10 | 2024-02-25 19:42:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "templates/debug.h"
#else
#define dbg(...) (void)0
#define msg(...) (void)0
#endif
#define ll long long
#define endl '\n'
#define PB emplace_back
#define PPB pop_back
#define MP make_pair
#define ALL(Name) Name.begin(),Name.end()
#define PII pair<int,int>
#define VI vector<int>
#define fi first
#define se second
int main()
{
ios::sync_with_stdio(false),cin.tie(nullptr);
int _;cin>>_;while(_--)
{
string s,t;
cin>>s>>t;
if(s.size()==1)
{
cout<<(s==t?0:-1)<<endl;
continue;
}
vector<PII>ops;
auto op=[&](int l,int r)
{
ops.PB(l+1,r+1);
ll num=0;
for(int i=l;i<=r;i++)
num=num*3+s[i]-'0';
s.erase(l,r-l+1);
string tmp;
while(num)tmp=char((num&1)+'0')+tmp,num>>=1;
s.insert(l,tmp);
};
for(int i=1,j=0;i<s.size();i++)
if(s[i]=='1')
{
if(i-j>1)op(j+1,i);
i=++j;
}
if(s.back()=='0')op(s.size()-2,s.size()-1);
for(int i=s.size()-2;i;i--)
op(i,i+1);
op(2,s.size()-1);
for(int i=t.size()-1;i>1;i--)
{
op(0,1);
op(0,1);
if(t[i]=='1')op(1,2);
}
if(t[1]=='0')op(0,1),op(1,2);
assert(s==t);
cout<<ops.size()<<endl;
for(auto i:ops)cout<<i.fi<<" "<<i.se<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 18 3 4 4 5 4 5 3 4 2 3 3 8 1 2 1 2 1 2 1 2 2 3 1 2 1 2 1 2 1 2 2 3 1 2 1 2 15 3 4 2 3 3 6 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3 1 2 1 2 2 3
result:
wrong answer S!=T after all operations (test case 2)