QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376154#8058. Binary vs TernaryEunoiayWA 0ms3828kbC++201.6kb2024-04-03 21:59:052024-04-03 21:59:05

Judging History

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

  • [2024-04-03 21:59:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-04-03 21:59:05]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
	string a, b;
	cin >> a >> b;

	if (a == "1") {
		cout << (b == "1" ? 0 : -1) << "\n";
		return;
	}

	int n = a.size();
	int m = b.size();	

	vector<pair<int, int>> ans;
	for (int i = 0; i + 1 < n; ++i) {
		if (a[i] == '1' && a[i + 1] == '0') {
			ans.emplace_back(i + 1, i + 2);
			a[i] = a[i + 1] = '1';
		}
	}

	while (a.size() < b.size()) {
		ans.emplace_back(n - 1, n);
		ans.emplace_back(n - 1, n + 1);
		ans.emplace_back(n - 1, n + 2);
		ans.emplace_back(n + 1, n + 3);
		a += '1';
 	}
 	while (a.size() > b.size()) {
 		ans.emplace_back(n - 1, n);
		ans.emplace_back(n - 1, n + 1);
		ans.emplace_back(n, n + 2);
		ans.pop_back();
 	}

 	n = m;
	for (int i = m - 1; i >= 0; --i) {
		if (b[i] == '0') {
			ans.emplace_back(n - 1, n);
			ans.emplace_back(n - 1, n);
			ans.emplace_back(n - 1, n);
			ans.emplace_back(n + 1, n + 2);
			a[i] = '0';
			--n;
		}
	}

	// cerr << a << "\n" << b << "\n";
	cout << ans.size() << "\n";
	for (auto [x, y] : ans) {
		cout << x << " " << y << "\n";
	}
}	

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	auto convert = [&](string s) {
		i64 x = 0;
		for (char c : s) {
			x = x * 3 + (c - '0');
		}

		string t;
		while (x) {
			t += x % 2 + '0';
			x /= 2;
		}
		reverse(t.begin(), t.end());
		return t;
	};

	/*
	 10
	 11
	 100
	 1001
	 11100
	*/
	// string tt = "110";
	// for (int i = 0; i < 10; ++i) {
	// 	cout << tt << "\n";
	// 	tt = convert(tt);
	// }

	int t;
	cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3828kb

input:

3
1
111
110110
1101010
1111
111111

output:

-1
18
2 3
5 6
5 6
5 7
5 8
7 9
6 7
6 7
6 7
8 9
5 6
5 6
5 6
7 8
4 5
4 5
4 5
6 7
8
3 4
3 5
3 6
5 7
3 4
3 5
3 6
5 7

result:

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