QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#338093#8058. Binary vs TernarySTnofarjo#WA 1ms3888kbC++201.3kb2024-02-25 17:42:462024-02-25 17:42:47

Judging History

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

  • [2024-02-25 17:42:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3888kb
  • [2024-02-25 17:42:46]
  • 提交

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()) {
		s = s.substr(0, t.size());
		sol.emplace_back((int)t.size(), (int)s.size() - 1);
		// 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;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3888kb

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: 3700kb

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 3
-1
9
1 2
2 3
3 4
4 5
3 4
2 3
3 2
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 2
6
2 3
4 5
4 5
3 4
2 3
3 2
3
2 3
2 3
3 2
-1
8
1 2
4 5
4 5
3 4
2 3
3 2
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 4
2 3
3 4
1 2
2 3
3
1 2
1 ...

result:

wrong answer (l,r) is invalid (test case 1)