QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#543362#8523. Puzzle IIucup-team4821#WA 1ms7712kbC++202.1kb2024-09-01 16:16:332024-09-01 16:16:33

Judging History

This is the latest submission verdict.

  • [2024-09-01 16:16:33]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7712kb
  • [2024-09-01 16:16:33]
  • Submitted

answer

#include <bits/stdc++.h>
int n, m, lst[600005], nxt[600005];
bool a[600005];
char x;
std::vector<std::pair<int, int>> op;
void connect(int A, int B)
{
    lst[nxt[A] = B] = A;
}
int ap, bp, al, ar, bl, br;
void swap()
{
    op.push_back({ap, bp});
    int lstal = lst[al], lstbl = lst[bl], nxtar = nxt[ar], nxtbr = nxt[br];
    connect(lstal, bl);
    connect(lstbl, al);
    connect(ar, nxtbr);
    connect(br, nxtar);
    std::swap(al, bl);
    std::swap(ar, br);
}
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin >> n >> m;
    for (int i = 1; i <= n + n; ++i)
        std::cin >> x, a[i] = x == 'C';
    if (std::count(a + 1, a + 1 + n, true) > std::count(a + 1, a + 1 + n, false))
    {
        for (int i = 1; i <= n + n; ++i)
            a[i] ^= true;
    }
    for (int i = 1; i <= n; ++i)
    {
        nxt[i] = i == n ? 1 : i + 1;
        lst[i] = i == 1 ? n : i - 1;
    }
    for (int i = n + 1; i <= n + n; ++i)
    {
        nxt[i] = i == n + n ? n + 1 : i + 1;
        lst[i] = i == n + 1 ? n + n : i - 1;
    }
    ap = 1, bp = 1, al = 1, ar = m, bl = n + 1, br = n + m;
    for (int i = 1; i <= n; ++i)
    {
        // std::cout << ap << ' ' << bp << std::endl;
        // for (int i = al, j = 1; j <= n; ++j, i = nxt[i])
        //     std::cout << a[i];
        // std::cout << std::endl;
        // for (int i = bl, j = 1; j <= n; ++j, i = nxt[i])
        //     std::cout << a[i];
        // std::cout << std::endl;
        if (a[nxt[ar]])
        {
            while (a[bl])
            {
                bp = bp % n + 1;
                bl = nxt[bl];
                br = nxt[br];
            }
            swap();
            ap = ap % n + 1;
            al = nxt[al];
            ar = nxt[ar];
            swap();
        }
        else
        {
            ap = ap % n + 1;
            al = nxt[al];
            ar = nxt[ar];
        }
    }
    std::cout << op.size() << std::endl;
    for (auto i : op)
    {
        std::cout << i.first << ' ' << i.second << std::endl;
    }
    return 0;
}

詳細信息

Test #1:

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

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: 1ms
memory: 5604kb

input:

2 1
BC
BC

output:

2
1 1
2 1

result:

ok moves = 2

Test #3:

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

input:

2 1
BB
CC

output:

0

result:

ok moves = 0

Test #4:

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

input:

2 1
CC
BB

output:

0

result:

ok moves = 0

Test #5:

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

input:

3 1
CCC
BBB

output:

0

result:

ok moves = 0

Test #6:

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

input:

3 1
CBC
BCB

output:

2
1 2
2 2

result:

ok moves = 2

Test #7:

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

input:

3 2
BBB
CCC

output:

0

result:

ok moves = 0

Test #8:

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

input:

3 2
BCB
BCC

output:

2
3 1
1 1

result:

ok moves = 2

Test #9:

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

input:

4 2
CCCB
BBCB

output:

2
2 3
3 3

result:

ok moves = 2

Test #10:

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

input:

9 6
CCCBCCCBB
BBBCBBBCC

output:

6
2 4
3 4
3 7
4 7
9 7
1 7

result:

ok moves = 6

Test #11:

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

input:

21 3
CCCCBBCBCCCCCCCBCCCCC
BBCCBCBBBBBBBBBCBBBBB

output:

8
2 3
3 3
3 3
4 3
5 6
6 6
13 16
14 16

result:

ok moves = 8

Test #12:

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

input:

49 41
CBCCBCCBCCBCCBCCCBBCCBCBBCCCBBCCBCBCBCBCCCCBCBCCB
BCCCCBCBBBBCBCBBBBBCBBBBCCCCBCBBCBBCBBBBCBCBCBBBC

output:

28
3 2
4 2
5 2
6 2
8 2
9 2
10 2
11 2
15 3
16 3
20 7
21 7
24 8
25 8
27 13
28 13
33 17
34 17
34 17
35 17
38 17
39 17
40 17
41 17
43 18
44 18
49 20
1 20

result:

wrong answer The final sequences are not correct!