QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213347#6644. Red Black Griducup-team228#WA 23ms3640kbC++204.7kb2023-10-14 13:51:232023-10-14 13:51:24

Judging History

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

  • [2023-10-14 13:51:24]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:3640kb
  • [2023-10-14 13:51:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e3 + 10;
char a[N][N];

bool getbit(int mask, int bit) {
    return mask & (1 << bit);
}

bool solve(int n, int k) {
    if (k == 0) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                a[i][j] = 'B';
            }
        }
        return true;
    } else if (n <= 4) {
        for (int mask = 0; mask < (1 << (n * n)); mask++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if (getbit(mask, (i - 1) * n + j - 1)) {
                        a[i][j] = 'R';
                    } else {
                        a[i][j] = 'B';
                    }
                }
            }
            int cur = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if ((i + j) % 2 == 0) {
                        if (i >= 2 && a[i][j] != a[i - 1][j]) cur++;
                        if (i <= n - 1 && a[i][j] != a[i + 1][j]) cur++;
                        if (j >= 2 && a[i][j] != a[i][j - 1]) cur++;
                        if (j <= n - 1 && a[i][j] != a[i][j + 1]) cur++;
                    }
                }
            }
            if (cur == k) {
                return true;
            }
        }
        return false;
    } else {
        int cnt[5] = {};
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if ((i + j) % 2 == 0) {
                    int cur = 0;
                    if (i >= 2) cur++;
                    if (i <= n - 1) cur++;
                    if (j >= 2) cur++;
                    if (j <= n - 1) cur++;
                    cnt[cur]++;
                }
            }
        }
        int trg[5] = {};
        bool ok = false;
        for (int i = 0; i <= cnt[4]; i++) {
            for (int j = 0; j <= cnt[2]; j++) {
                if (k >= 4 * i + 2 * j && (k - 4 * i - 2 * j) % 3 == 0 && (k - 4 * i - 2 * j) <= cnt[3]) {
                    trg[2] = j;
                    trg[3] = (k - 4 * i - 2 * j) / 3;
                    trg[4] = i;
                    ok = true;
                }
            }
        }
        if (ok) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    if ((i + j) % 2 == 0) {
                        int cur = 0;
                        if (i >= 2) cur++;
                        if (i <= n - 1) cur++;
                        if (j >= 2) cur++;
                        if (j <= n - 1) cur++;
                        if (trg[cur]) {
                            a[i][j] = 'R';
                            trg[cur]--;
                        } else {
                            a[i][j] = 'B';
                        }
                    } else {
                        a[i][j] = 'B';
                    }
                }
            }
            return true;
        } else {
            return false;
        }
    }
}

void foo() {
    int n = 3;
    int cnt[5] = {};
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if ((i + j) % 2 == 0) {
                int cur = 0;
                if (i >= 2) cur++;
                if (i <= n - 1) cur++;
                if (j >= 2) cur++;
                if (j <= n - 1) cur++;
                cnt[cur]++;
            }
        }
    }
    set<int> s;
    for (int i = 0; i <= cnt[4]; i++) {
        for (int j = 0; j <= cnt[3]; j++) {
            for (int k = 0; k <= cnt[2]; k++) {
                for (int l = 0; l <= cnt[1]; l++) {
                    for (int x = 0; x <= cnt[0]; x++) {
                        s.insert(4 * i + 3 * j + 2 * k + 1 * l + 0 * x);
                    }
                }
            }
        }
    }
    cout << 0 << " " << 2 * n * (n - 1) << "\n";
    for (int i : s) {
        cout << i << " ";
    }
    cout << "\n";
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    // foo();

    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        if (solve(n, k)) {
            cout << "Possible\n";
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    cout << a[i][j];
                }
                cout << "\n";
            }
        } else {
            cout << "Impossible\n";
        }
    }

#ifdef LOCAL
    cout << "\nTime elapsed: " << double(clock()) / CLOCKS_PER_SEC << " s.\n";
#endif
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 6
3 1

output:

Possible
BRB
RBB
BBB
Impossible

result:

ok correct! (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 23ms
memory: 3640kb

input:

4424
1 0
2 4
2 3
2 2
2 1
2 0
3 12
3 11
3 10
3 9
3 8
3 7
3 6
3 5
3 4
3 3
3 2
3 1
3 0
4 24
4 23
4 22
4 21
4 20
4 19
4 18
4 17
4 16
4 15
4 14
4 13
4 12
4 11
4 10
4 9
4 8
4 7
4 6
4 5
4 4
4 3
4 2
4 1
4 0
5 40
5 39
5 38
5 37
5 36
5 35
5 34
5 33
5 32
5 31
5 30
5 29
5 28
5 27
5 26
5 25
5 24
5 23
5 22
5 21
5...

output:

Possible
B
Possible
BR
RB
Impossible
Possible
RB
BB
Impossible
Possible
BB
BB
Possible
BRB
RBR
BRB
Impossible
Possible
RBR
BRB
RBB
Possible
BRB
RBR
BBB
Possible
RBR
BRB
BBB
Possible
BBR
RRB
BBB
Possible
BRB
RBB
BBB
Possible
BBR
RBB
BBB
Possible
RBR
BBB
BBB
Possible
BRB
BBB
BBB
Possible
RBB
BBB
BBB
I...

result:

wrong answer Condition failed: "A == B" (test case 45)