QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214335#6644. Red Black GridzzzzWA 17ms3528kbC++172.4kb2023-10-14 18:51:452023-10-14 18:51:46

Judging History

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

  • [2023-10-14 18:51:46]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3528kb
  • [2023-10-14 18:51:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i, j, k) for (ll i = j; i <= k; ++i)
#define per(i, j, k) for (ll i = j; i >= k; --i)
#define closeSync            \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define pii pair<ll, ll>
#define fi first
#define se second
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

void solve() {
    ll n, k;
    cin >> n >> k;
    ll lim = 2 * n * (n - 1);
    if (k == 1 || k == lim - 1) {
        cout << "Impossible\n";
        return;
    }
    cout << "Possible\n";
    vector<vector<int>> mp(n + 1, vector<int>(n + 1, 0));
    if (n <= 4) {
        for (int sta = 0; sta < (1 << n * n); ++sta) {
            for (int j = 0; j < n * n; ++j) {
                bool f = (sta >> j) & 1;
                mp[j / n + 1][j % n + 1] = f;
            }
            int cnt = 0;
            rep(i, 1, n) {
                rep(j, 2, n) {
                    if (mp[i][j] != mp[i][j - 1]) cnt++;
                    if (mp[j][i] != mp[j - 1][i]) cnt++;
                }
            }
            if (cnt == k) {
                rep(i, 1, n) {
                    rep(j, 1, n) {
                        if (mp[i][j] == 1)
                            cout << "R";
                        else
                            cout << "B";
                    }
                    cout << "\n";
                }
                return;
            }
        }
    }
    int f = 0;
    if (k > lim / 2) {
        k = k - lim / 2;
        f = 1;
    }
    if (k & 1) {
        mp[1][3] = 1;
        k -= 3;
    }
    if (k % 4) {
        mp[1][1] = 1;
    }
    k /= 4;
    int x = 2, y = 2;
    while (k--) {
        mp[x][y] = 1;
        y += 2;
        if (y >= n) {
            x++;
            if (x & 1) {
                y = 3;
            } else {
                y = 2;
            }
        }
    }

    if (f) {
        rep(i, 1, n) {
            rep(j, 1, n) {
                if (i + j & 1) mp[i][j] ^= 1;
            }
        }
    }
    rep(i, 1, n) {
        rep(j, 1, n) {
            if (mp[i][j] == 1)
                cout << "R";
            else
                cout << "B";
        }
        cout << "\n";
    }
}

int main() {
    closeSync;
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 17ms
memory: 3528kb

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: "getNum(vec) == k" (test case 45)