QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338267#8058. Binary vs TernaryYMH_fourteenRE 0ms3532kbC++141.3kb2024-02-25 19:48:592024-02-25 19:49:00

Judging History

你现在查看的是最新测评结果

  • [2024-02-25 19:49:00]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3532kb
  • [2024-02-25 19:48:59]
  • 提交

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||t.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;
		if(!num)tmp="0";
		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()-3;~i;i--)
		op(i,i+1);
	op(1,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: 100
Accepted
time: 0ms
memory: 3532kb

input:

3
1
111
110110
1101010
1111
111111

output:

-1
18
3 4
4 5
3 4
2 3
1 2
2 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
2 3
1 2
2 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:

ok Haitang Suki (3 test cases)

Test #2:

score: -100
Runtime Error

input:

1000
11100
111
1
11110
10001
10
1011
1111
10
1110
1100
11
11010
11
110
11
1
10001
10110
10
10
11111
10000
1001
10
1
11
10111
11
10
1
100
11
10100
1
10
101
11
1100
110
11
1110
1
1001
1
11111
10
10010
10
11001
110
1010
10011
1110
10100
1001
1001
101
100
1
1001
11
101
11
101
1001
1
1
1011
1
10
10
1011
...

output:


result: