QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#338126#8058. Binary vs TernarySTnofarjo#WA 1ms3580kbC++201.4kb2024-02-25 18:06:152024-02-25 18:06:17

Judging History

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

  • [2024-02-25 18:06:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2024-02-25 18:06:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void solve() {
	string s, t;
	cin >> s >> t;

	if (s.size() == 1 && s != t) {
		cout << "-1\n";
		return;
	}

	vector<pair<int, int>> sol;

	while (s.size() < t.size()) {
		if (s[1] == '0') {
			sol.emplace_back(0, 1);
			s[1] = '1';
		} else {
			s = "100" + s.substr(2, s.size() - 2);
			sol.emplace_back(0, 1);
		}
		// cout << s << '\n';
	}

	for (int i=1; i<(int)s.size(); i++) {
		if (s[i] == '0') {
			s[i] = '1';
			sol.emplace_back(i-1, i);
			// cout << s << '\n';
		}
	}

	for (int i=(int)s.size()-1; i>=(int)t.size(); i--) {
		s = s.substr(0, i) + "00" + (i+1 < (int)s.size() ? s.substr(i+1, s.size()-i-1) : "");
		sol.emplace_back(i-1, i);
		// cout << s << '\n';
	}
	if (s.size() > t.size()) {
		sol.emplace_back((int)t.size(), (int)s.size() - 1);
		s = s.substr(0, t.size());
		// cout << s << '\n';
	}

	for (int i=(int)s.size()-1; i>0; i--) {
		if (t[i] == '0') {
			s[i] = '0';
			sol.emplace_back(i-1, i);
			sol.emplace_back(i, i+1);
			// cout << s << '\n';
		}
	}

	cout << sol.size() << '\n';
	for (auto &[l, r] : sol) {
		cout << l+1 << ' ' << r+1 << '\n';
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int tcs;
	cin >> tcs;
	while (tcs--) {
		solve();
	}
	return 0;
}

/*
6
1
1

10101010
11010101

10101010
11

10101
10010010

1111
1111

111000110
1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3516kb

input:

3
1
111
110110
1101010
1111
111111

output:

-1
11
1 2
1 2
2 3
3 4
6 7
6 7
7 8
4 5
5 6
2 3
3 4
6
1 2
1 2
1 2
1 2
2 3
3 4

result:

ok Haitang Suki (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3580kb

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:

5
3 4
4 5
4 5
3 4
4 7
-1
9
1 2
2 3
3 4
4 5
3 4
2 3
3 8
1 2
2 3
1
1 2
9
1 2
1 2
1 2
1 2
1 2
2 3
3 4
3 4
4 5
5
2 3
3 4
3 4
2 3
3 6
6
2 3
4 5
4 5
3 4
2 3
3 8
3
2 3
2 3
3 4
-1
8
1 2
4 5
4 5
3 4
2 3
3 8
1 2
2 3
10
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 3
3 4
4 5
10
1 2
2 3
3 4
4 5
4 5
5 6
2 3
3 4
1 2
2 3
3
1 2
1 ...

result:

wrong answer S!=T after all operations (test case 1)