QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446634#8523. Puzzle IIucup-team045WA 1ms3820kbC++201.7kb2024-06-17 14:32:222024-06-17 14:32:23

Judging History

This is the latest submission verdict.

  • [2024-06-17 14:32:23]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3820kb
  • [2024-06-17 14:32:22]
  • Submitted

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<deque>
#include<algorithm>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++){
        char c;
        cin >> c;
        a[i] = (c == 'B');
    }
    for(int i = 0; i < n; i++){
        char c;
        cin >> c;
        b[i] = (c == 'B');
    }
    int c1 = 0, c2 = 0;
    int cnt = count(a.begin(), a.end(), 1);
    if (cnt * 2 >= n){
        c1 = 1;
        c2 = 0;
    }
    else{
        c1 = 0;
        c2 = 1;
        cnt = n - cnt;
    }
    vector<pair<int, int> > ans;
    deque<int> q1(a.begin(), a.begin() + k);
    deque<int> q2(b.begin(), b.begin() + k);

    int p1 = 0, p2 = 0;
    auto swp = [&](){
        ans.push_back({p1, p2});
        q1.swap(q2);
        a[p1] = q1.front();
        q1.pop_front();
        q1.push_back(a[(p1 + k) % n]);
        p1 = (p1 + 1) % n;
        ans.push_back({p1, p2});
        q1.swap(q2);
    };
    
    for(int i = 0; i < n - cnt; i++){
        while(a[(p1 + k) % n] == c1){
            a[p1] = q1.front();
            q1.pop_front();
            q1.push_back(a[(p1 + k) % n]);
            p1 = (p1 + 1) % n;
        }
        while(q2.front() == c2){
            a[p2] = q2.front();
            q2.pop_front();
            q2.push_back(b[(p2 + k) % n]);
            p2 = (p2 + 1) % n;
        }
        swp();
    }
    cout << ans.size() << '\n';
    for(auto [x, y] : ans){
        cout << x + 1 << ' ' << y + 1 << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 3
BCCBCC
BBCBBC

output:

4
1 3
2 3
5 6
6 6

result:

ok moves = 4

Test #2:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

2 1
BC
BC

output:

2
1 1
2 1

result:

ok moves = 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

2 1
BB
CC

output:

0

result:

ok moves = 0

Test #4:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

2 1
CC
BB

output:

0

result:

ok moves = 0

Test #5:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

3 1
CCC
BBB

output:

0

result:

ok moves = 0

Test #6:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

3 1
CBC
BCB

output:

2
1 2
2 2

result:

ok moves = 2

Test #7:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

3 2
BBB
CCC

output:

0

result:

ok moves = 0

Test #8:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

3 2
BCB
BCC

output:

2
3 1
1 1

result:

ok moves = 2

Test #9:

score: 0
Accepted
time: 1ms
memory: 3764kb

input:

4 2
CCCB
BBCB

output:

2
2 3
3 3

result:

ok moves = 2

Test #10:

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

input:

9 6
CCCBCCCBB
BBBCBBBCC

output:

6
2 4
3 4
3 7
4 7
4 7
5 7

result:

wrong answer The final sequences are not correct!