QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#356541#6442. Secret of Tianqiu ValleyPorNPtreeWA 1ms3904kbC++142.4kb2024-03-17 22:40:142024-03-17 22:40:14

Judging History

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

  • [2024-03-17 22:40:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3904kb
  • [2024-03-17 22:40:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int n;
string S, T;
vector<int> res;
set<int> z[2][2];

void add(int x)
{
    assert(S[x] == '1');
    res.push_back(x);
    z[S[(x + n - 1) % n] - '0'][T[(x + n - 1) % n] - '0'].erase((x + n - 1) % n);
    z[S[x] - '0'][T[x] - '0'].erase(x);
    z[S[(x + 1) % n] - '0'][T[(x + 1) % n] - '0'].erase((x + 1) % n);
    S[(x + n - 1) % n] ^= 1;
    S[x] ^= 1;
    S[(x + 1) % n] ^= 1;
    T[x] ^= 1;
    z[S[(x + n - 1) % n] - '0'][T[(x + n - 1) % n] - '0'].insert((x + n - 1) % n);
    z[S[x] - '0'][T[x] - '0'].insert(x);
    z[S[(x + 1) % n] - '0'][T[(x + 1) % n] - '0'].insert((x + 1) % n);
    return;
}

signed main()
{
    int tests;
    scanf("%d", &tests);
    while (tests--) {
        scanf("%d", &n);
        T = "";
        cin >> S;
        for (int i = 0; i < n; ++i) {
            S[i] ^= 1;
        }
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                T += (char)(i + '0');
                T += (char)(j + '0');
                for (int k = 1; k < n - 1; ++k) {
                    T += (char)(T[k - 1] ^ T[k] ^ S[k]);
                }
                if ((T[0] ^ T[1] ^ T[n - 1]) == S[0] && (T[n - 2] ^ T[n - 1] ^ T[0]) == S[n - 1]) {
                    break;
                }
                T = "";
            }
            if (!T.empty()) {
                break;
            }
        }
        if (T.empty()) {
            puts("0");
            continue;
        }
        z[0][0].clear(), z[0][1].clear();
        z[1][0].clear(), z[1][1].clear();
        for (int i = 0; i < n; ++i) {
            z[S[i] - '0'][T[i] - '0'].insert(i);
        }
        while (z[1][0].size() || z[1][1].size()) {
            if (z[1][1].size()) {
                add(*z[1][1].begin());
            } else {
                int x = *z[1][0].begin(), y, z;
                if (T[(x + 1) % n] == '1') {
                    y = (x + 1) % n, z = (y + 1) % n;
                } else {
                    y = (x + n - 1) % n, z = (y + n - 1) % n;
                }
                add(x), add(y), add(x), add(z);
            }
        }
        printf("%d\n", (int)res.size());
        for (int i = 0; i < (int)res.size(); ++i) {
            printf("%d%c", res[i] + 1, " \n"[i + 1 == (int)res.size()]);
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3904kb

input:

2
5
00000
3
001

output:

7
1 3 2 1 5 1 4
0

result:

ok all puzzle solved (2 test cases)

Test #2:

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

input:

7
3
000
3
100
3
010
3
110
3
001
3
101
3
011

output:

1
3
0
0
0
0
0
0

result:

ok all puzzle solved (7 test cases)

Test #3:

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

input:

15
4
0000
4
1000
4
0100
4
1100
4
0010
4
1010
4
0110
4
1110
4
0001
4
1001
4
0101
4
1101
4
0011
4
1011
4
0111

output:

4
1 3 2 4
5
1 3 2 4 3
6
1 3 2 4 3 4
10
1 3 2 4 3 4 3 2 3 1
11
1 3 2 4 3 4 3 2 3 1 1
13
1 3 2 4 3 4 3 2 3 1 1 2 4
17
1 3 2 4 3 4 3 2 3 1 1 2 4 1 2 1 3
20
1 3 2 4 3 4 3 2 3 1 1 2 4 1 2 1 3 4 1 3
21
1 3 2 4 3 4 3 2 3 1 1 2 4 1 2 1 3 4 1 3 2
25
1 3 2 4 3 4 3 2 3 1 1 2 4 1 2 1 3 4 1 3 2 2 1 2 4
27
1 3 2 ...

result:

wrong answer ignite ignited torch (test case 2)