QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#794765#8527. Power DivisionswangjunruiWA 0ms3808kbC++141.7kb2024-11-30 15:56:132024-11-30 15:56:14

Judging History

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

  • [2024-11-30 15:56:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-11-30 15:56:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 3e5 + 5;
int n, m;
char A[N], B[N];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> m >> A >> B;
	int cnt = 0;
	for (int i = 0; i < n; ++i)
		cnt += (A[i] == 'B');
	
	list<char> a, b;
	for (int i = 0; i < m; ++i)
		a.push_back(A[i]);
	for (int i = n - m; i < n; ++i)
		b.push_back(B[i]);
	b.push_back(B[0]);
	
	vector<pair<int, int>> answer;
	
	if (cnt <= n / 2)
	{
		for (int i = m - 1, j = 0; cnt--;)
		{
			while (a.front() != 'B')
			{
				A[(i - a.size() + 1 + n) % n] = a.front();
				a.pop_front();
				a.push_back(A[i = (i + 1) % n]);
			}
			while (b.back() != 'C')
			{
				B[(j - b.size() + 1 + n) % n] = b.front();
				b.pop_front();
				b.push_back(B[j = (j + 1) % n]);
			}
			answer.emplace_back((i - m + 1 + n) % n, (j - m + n) % n);
			answer.emplace_back((i - m + 1 + n) % n, (j - m + 1 + n) % n);
			a.pop_front(), b.pop_back();
			a.push_back('C'), b.push_front('B');
		}
	}
	else
	{
		cnt = n - cnt;
		for (int i = m - 1, j = 0; cnt--;)
		{
			while (a.front() != 'C')
			{
				A[(i - a.size() + 1 + n) % n] = a.front();
				a.pop_front();
				a.push_back(A[i = (i + 1) % n]);
			}
			while (b.back() != 'B')
			{
				B[(j - b.size() + 1 + n) % n] = b.front();
				b.pop_front();
				b.push_back(B[j = (j + 1) % n]);
			}
			answer.emplace_back((i - m + 1 + n) % n, (j - m + n) % n);
			answer.emplace_back((i - m + 1 + n) % n, (j - m + 1 + n) % n);
			a.pop_front(), b.pop_back();
			a.push_back('B'), b.push_front('C');
		}
	}
	cout << answer.size() << '\n';
	for (auto [u, v] : answer)
		cout << u + 1 << ' ' << v + 1 << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 0 0 1 1

output:

0

result:

wrong answer 1st numbers differ - expected: '6', found: '0'