QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#794667 | #8523. Puzzle II | wangjunrui | WA | 0ms | 3556kb | C++14 | 1.6kb | 2024-11-30 15:27:02 | 2024-11-30 15:27:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1.5e5 + 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');
deque<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--; ++i)
{
while (a.front() != 'B')
{
a.pop_front();
a.push_back(A[i = (i + 1) % n]);
}
while (b.back() != 'C')
{
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();
swap(a, b);
a.push_back('C');
b.push_front('B');
}
}
else
{
cnt = n - cnt;
for (int i = m - 1, j = 0; cnt--; ++i)
{
while (a.front() != 'C')
{
a.pop_front();
a.push_back(A[i = (i + 1) % n]);
}
while (b.back() != 'B')
{
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();
swap(a, b);
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: 3556kb
input:
6 3 BCCBCC BBCBBC
output:
4 1 6 1 1 3 6 3 1
result:
wrong answer The final sequences are not correct!